c++ - invalid initialization of non-const reference of type in gcc but not Visual Studio -


i have code iinterface abstract class.

i writing

iinterface &q  = interfaceimpl(); 

and compiled in visual studio 2008 , worked fine. ported gcc project , got error:

error: invalid initialization of non-const reference of type 'iinterface&' temporary of type 'interfaceimpl' 

when trying find out wrong found thread error: invalid initialization of non-const reference of type ‘int&’ rvalue of type ‘int’ , @ least understand wrong. changing this:

interfaceimpl = interfaceimpl(); iinterface &q = i; 

made compile:

however, lifetime of these 2 objects same, don't understand why gcc can not create temporary object apparently ms did. assume defined standard? when @ link above, can understand why makes no sense base type, why need error in case of object?

i tried this, error iinterface abstract class , can not instantiated.

iinterface = interfaceimpl(); 

i should initialized, not instantiated. mean need copy constructor or assignment operator in interfaceimpl make work or why error?

interfaceimpl() returns temporary object (rvalue) cannot keep in non-const reference.

however when instantiate iinterface i becomes lvalue, can keep in non-const reference.

however binding non-const reference rvalue allowed in vs . has been discussed in thread


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -