Reputation:
I'm confused about using pointers and references and I'm facing a little problem.
I got a function :
bool myObject::isFlag( QString &pArgument) const { }
And I'm using it with :
QStringList::const_iterator myQStringList.begin();
[...] && !isFlag( QString( *(myVar + 1)))
I got an error for the
QString( *(myVar + 1)))
which specifies taht no matching function is found.
However I'm pretty sure this should be good ... do you happen to know what could be the problem ?
Upvotes: 2
Views: 2946
Reputation: 227400
In this call
isFlag( QString( *(myVar + 1)))
the argument is a temporary QString
. You cannot bind non-const references to temporaries, you you would need to change isFlag
to take a const reference:
bool myObject::isFlag( const QString &pArgument) const {
If you cannot use a const
reference, then you should create a QString
, then pass it to the function:
QString qs( *(myVar + 1));
isFlag(qs);
All of the above assumes that a QString
can be constructed from, *(myvar +1)
, which is, again, a temporary.
Upvotes: 4