class B
{
public:
B(){n=0;}
B(int nn){n=nn;}
void f(){cout << "f\n";}
void g(){cout << "g\n";}
private:
int n;
};
class D: private B
{
public:
D(int nn, float dd): B(nn), d(dd){}
void h(){ f(); cout << "h\n";}// h calls f
private:
double d;
};
int main ()
{
D d(5,3);
d.h();// OK. Calling f in a D member function is OK.
d.f();// Not OK. See below
||=== Build: Release in forumProbs (compiler: GNU GCC Compiler) ===|
C:\codeBlocksProjects\forumProbs\main.cpp||In function 'int main()':|
C:\codeBlocksProjects\forumProbs\main.cpp|29|error: 'void B::f()' is inaccessible|
C:\codeBlocksProjects\forumProbs\main.cpp|47|error: within this context|
C:\codeBlocksProjects\forumProbs\main.cpp|47|error: 'B' is not an accessible base of 'D'|
||=== Build failed: 3 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===| */
cout << '\n';
return 0;
}
It appears that calling f or g in a D class member function is OK, but calling f or g directly in main is not.