Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I do not understand this C++ error - error C2101: '&' on constant

This code supposedly works with GCC - I am trying to get it to work with Visual Studio. I can't figure out if the code is actually faulty or I'm not doing something right with the port.

1>c:\somepath\aaa.h(52): error C2101: '&' on constant
1>          c:\somepath\aaa.h(52): while compiling class template member function 'const blahblah::Message something::AClass<Type>::aMethod(void) const'
1>          with
1>          [
1>              Type=const lala::BClass&
1>          ]
1>          c:\somepath\bbb.h(79) : see reference to class template instantiation 'something:AClass<Type>' being compiled
1>          with
1>          [
1>              Type=const lala::BClass&
1>          ]
1>  MyApplication.cpp

Files

aaa.h:52          virtual const Type aMethod() const { return Type(); }

bbb.h:79          AClass<const BClass&> blahblahblah_;
like image 503
marathon Avatar asked Sep 17 '11 23:09

marathon


1 Answers

Constructing T() where T is a reference type is not valid, and makes no sense. Some versions of gcc incorrectly accept it.

like image 93
servn Avatar answered Sep 27 '22 21:09

servn