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

后端 未结 1 1853
广开言路
广开言路 2021-01-23 16:36

I have some code where IInterface is an abstract class.

I was writing this

IInterface &q  = InterfaceImpl();

and compiled it in Vi

相关标签:
1条回答
  • 2021-01-23 16:54

    InterfaceImpl() returns a temporary object (rvalue) that you cannot keep in a non-const reference.

    However when you instantiate IInterface i i becomes an lvalue, So you can keep it in non-const reference.

    However binding non-const reference to rvalue is allowed in VS . It has been discussed in this thread

    0 讨论(0)
提交回复
热议问题