c++ inheritance

Started by
4 comments, last by erjo 22 years, 1 month ago
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
Advertisement
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]
Bobby Ward - COM Guru in training
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
Thanks everyone, worked perfectly.

Eric
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.

^ Depends on what the classes are and what you''re doing with them.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

This topic is closed to new replies.

Advertisement