0

i have those 2 pieces of code, which seem to be equivalent to me, but one gives me a compiler error and the other does not.

I return a QString from one function and pass by reference to another one:

void takesAQString(QString& s){}
QString returnsAQString(){QString s = "Hello"; return s;}

QString s = returnsAQString();
QString ss = "Hello";
takesAQString(s); //this compiles without error
takesAQString(ss); //this too
takesAQString(returnsAQString()); //this gives me an error

This gives me error: no matching function to call '...takesAQString(QString)' and note: candidates are: ... takesAQString(QString&)

Well the error itself is pretty clear, but to me the above 3 ways of passing in the QString seem to be 100% equivalent to me. What am i missing?

tobilocker
  • 891
  • 8
  • 27

0 Answers0