Главная страница | назад





Article #18720: public vs private inheritance

 Question and Answer Database
FAQ3720C.txt public vs private inheritance
Category :Compiler
Platform :All
Product : BC++4.5x BC++5.x C++Builder1.0 C++Builder3.x TC++Dos3.0 TC++Win4.5
Question:
I have the following question. Given:
class A {
public:
int V; int Avar;
A(){};
};
class B {
public:
int V;
B(){};
int Bvar;
};
class C : public A, B
{
public:
C(){};
int Cvar;
};
void main(void)
{
C abc;
abc.Avar = 3;
abc.Bvar = 2;
}
why do I get that abc.Bvar is not accessible?
Answer:
The inherited class B becomes a private class due to the way you have defined
class C.
You need to change
class C: public A, B
to
class C: public A, public B
8/26/98 2:29:02 PM

Last Modified: 01-SEP-99