PDA

View Full Version : passing as 'this' argument of discards qualifiers



yyiu002
22nd June 2010, 00:22
Hi , I have a problem when compile following code:


for(int i=0;i<curConnections.size();++i)
{
if (curConnections.at(i).Descriptor()==connName)
{
curConnections.at(i).sendCmd(cmd);
break;
}
}


Compiler complains:
error: passing 'const ConnConnection' as 'this' argument of 'void ConnConnection::sendCmd(const QString&)' discards qualifiers

Then I use following it compiles OK.



curConnections[i].sendCmd(cmd);


I am not quite get what's the difference of these 2 lines of code.

franz
22nd June 2010, 07:50
at() is a const function and returns a const object. operator[]() is non-const.

yyiu002
22nd June 2010, 22:35
many thanks