PDA

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



yyiu002
21st June 2010, 23: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, 06:50
at() is a const function and returns a const object. operator[]() is non-const.

yyiu002
22nd June 2010, 21:35
many thanks