1
class test{
    static const int veryprivate=3;
};

const int anarray[]={test::veryprivate};

g++巧妙地指出,anarray它既不是函数也不是成员函数。是否可以修复此代码保留veryprivate private?接受 C++11。

4

1 回答 1

2

anarray一个数组引用:

class test {
    static const int veryprivate = 3;
    friend class animpl;
};
class animpl {
public:
    static const int anarray[] = { test::veryprivate };
};
auto &anarray = animpl::anarray;
于 2012-12-05T10:03:59.110 回答