c++ - Inaccessible inherited public property -


this question has answer here:

i've tried making basic c++ program classes , ran problem. program looks like:

#include<iostream> using namespace std;  class { public:     int i;     a(int ai) {this->i = ai;}     a() {} };  class b : { public:     aa;     b(a &a) : a(a.i) {         aa = a;     } };  int main() {     a(5);     b b(a);      cout << "hello world!" << b.i;     return 0; } 

the program fails compile with:

in function 'int main()': line 6: error: 'int a::i' inaccessible compilation terminated due -wfatal-errors. 

but variable i public in class a. doing wrong?

you're inheriting a privately:

class b : {        ^^^^^^ 

you need inherit a publicly:

class b : public {        ^^^^^^^^^^^^^ 

Comments