c – 朋友类无法访问受保护的成员

代码曾用于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(){} ).

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...