Why doesn't gcc compile class declaration as a reference argument?

This compiles in Visual Studio, but why not in Xcode?

class A()
{};

someMethod(A& a);

someMethod(A()); //error: no matching function call in XCode only :(  

Is this a bad shape? It seems annoying to write the following every time:

A a;
someMethod(a);  //successful compile on Xcode

Am I missing something? I am not very experienced, so thanks for any help!

+2
source share
2 answers

You cannot bind a temporary link to a non-constant link. It will work if you change the function to take a reference to a constant:

someMethod(const A& a);

Besides,

A a();

does not declare a local variable. It declares a function with a name athat takes no parameters and returns an object of type a. Do you mean:

A a;
+4
source

rvalues ​​( ), someMethod(A()), . , ( )

void someMethod(const A& a);
0

All Articles