此代码曾用于Visual Studio 2015,但它不再适用于Visual Studio 2015更新1.
class Foo { protected: virtual ~Foo() {}; friend class Foo__init; }; class Foo__init { public: Foo _init; }; static Foo__init _Foo_init;
它失败并出现以下错误:
Error C2248 'Foo::~Foo': cannot access protected member declared in class 'Foo'
解决方法
从
here开始:
The friend declaration appears in a class body and grants a function or another class access to private and protected members of the class where the friend declaration appears.
所以这是一个编译器错误. g(Ubuntu 5.2.1-22ubuntu2)5.2.1 20151010和Ubuntu clang版本3.6.2-1(标签/ RELEASE_362 / final)(基于LLVM 3.6.2)编译此代码(我添加了int main(){} ).
原文地址:https://www.jb51.cc/c/117806.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。