我不明白这个 C++错误 - 错误 C2101:'&'恒定

发布于 2024-12-04 21:19:16 字数 872 浏览 2 评论 0原文

这段代码应该可以与 GCC 一起使用 - 我正在尝试让它与 Visual Studio 一起使用。我无法弄清楚代码实际上是否有错误,或者我没有对端口做正确的事情。

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

文件

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

bbb.h:79          AClass<const BClass&> blahblahblah_;

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_;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沧桑㈠ 2024-12-11 21:19:16

构造 T() (其中 T 是引用类型)是无效的,并且没有任何意义。某些版本的 gcc 错误地接受它。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文