c++ inheritance
Hi.
I''ve been experimenting some with classes, and I have a small problem I''ve been fighting with for 3 days now. Help is very appreciated. =)
Basically, I have a class:
class a
{
protected:
int iAVar;
};
Then I have another class inheriting it..
class b : a
{
// Stuff, nothing of importance for this problem.
};
And then last, and this is where my problem is(either here or in "a"..
class c : b
{
public:
void DoStuff() { iAVar = 2; }
};
However, this gives me this:
error C2247: ''iAVar'' not accessible because ''b'' uses ''private'' to inherit from ''a''
Anyone got any ideas? And yes, this code is faked, but I could give you the real thing if you want.
Thanks.
Eric
unless you do state it explicitly, its assumed its private.
ex.
class a
{
protected:
int i;
};
class b: public a
{
};
class c : private b
{
void do_it()
{
i = 0;
}
};
[edited by - KlePt0 on March 21, 2002 2:14:22 PM]
ex.
class a
{
protected:
int i;
};
class b: public a
{
};
class c : private b
{
void do_it()
{
i = 0;
}
};
[edited by - KlePt0 on March 21, 2002 2:14:22 PM]
class a
{
protected:
int iAVar;
};
class b : public a
{
// Stuff, nothing of importance for this problem.
};
class c : public b
{
public:
void DoStuff() { iAVar = 2; }
};
that should work
{
protected:
int iAVar;
};
class b : public a
{
// Stuff, nothing of importance for this problem.
};
class c : public b
{
public:
void DoStuff() { iAVar = 2; }
};
that should work
what about encapsulation?
why do you have a protected member?
best to make it private and manipulate with protected member functions if you only want derived classes to access it.
why do you have a protected member?
best to make it private and manipulate with protected member functions if you only want derived classes to access it.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement