struct A { private: static int x; }; int A::x = 0; struct B: public A { void foo() { std::cout << x; } }; Why gives an error:
[Error] 'int A :: x' is private
?
struct A { private: static int x; }; int A::x = 0; struct B: public A { void foo() { std::cout << x; } }; Why gives an error:
[Error] 'int A :: x' is private
?
Source: https://ru.stackoverflow.com/questions/517126/
All Articles
int A::x = 0;Initialize your variable in structure A - Alexey Sarovskyxfrom a classBmethod. In classBxmember is not available for direct conversion, since defined in classAin theprivatesection. The correct answer from @Harry is below. - aleks.andr