What does this error mean?
error: no matching function for call to `foo::bar(Qux (&)())`
I understand that the compiler (g++) is failing to match a function call with a foo member function. I am asking specifically about the extra stuff at the end; this bit: (&)().
For reference, my function call is like this:
// inside another member function of `foo`
Qux qux();
this->bar(qux);
And the signature for bar is:
virtual void bar(Qux&);
The compiler is also saying that the only candidate is:
virtual void bar(Qux&);
How does my function call signature differ from my definition signature, and what does (&)() mean?
Well, (&)() alone doesn't mean anything. (&)() is just a part of Qux (&)() which means reference to a function which takes nothing and return Qux. And this arises because of this:
Qux qux(); //PROBLEM!
this->bar(qux);
The first line here does NOT declare an object. It declares a function instead.
Search for vexing parse in C++, on this site, you'll see lots of topic on it, that discuss this problem in detail.
You should use Qux qux; (or alternatively in C++11 Qux qux{};) to avoid the most vexing parse.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With