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

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

g++ smartly points out that anarray is neither a function or a member function. Is it possible to fix this code keeping veryprivate private? C++11 accepted.

Lorenzo Pistone
  • 5,028
  • 3
  • 34
  • 65

1 Answers1

2

Make anarray an array reference:

class test {
    static const int veryprivate = 3;
    friend class animpl;
};
class animpl {
public:
    static const int anarray[] = { test::veryprivate };
};
auto &anarray = animpl::anarray;
ecatmur
  • 152,476
  • 27
  • 293
  • 366