class test{
static const int veryprivate=3;
};
const int anarray[]={test::veryprivate};
g++
巧妙地指出 anarray
既不是函数也不是成员函数。是否可以修复此代码以保持 veryprivate
private
?接受 C++11。
最佳答案
使 anarray
成为数组引用:
class test {
static const int veryprivate = 3;
friend class animpl;
};
class animpl {
public:
static const int anarray[] = { test::veryprivate };
};
auto &anarray = animpl::anarray;
关于c++ - 静态初始化器的上下文是什么,我如何声明它的友元?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13616479/