Double inheritance?

I have a question about class extending please excuse my english, I have problem expressing with words, but here is the problem:

Assuming I have a class:

1
2
3
4
5
6
7
class BasicNeed
{
private:
string Name;
string Description;
public:
void setName(string name);  
void setDescription(string des); <---- access method
}

now i have another class that extend this class
1
2
3
4
5
6
7
8
9
class Object : BasicNeed
{
public:
Object()
{
setName("null");
setDescription("null");
}
}


NOW ANOTHER class:
1
2
3
4
5
6
7
class Item : Object
{
public:
Item(string name, string des)
{
setName(name);
setDescription(des);   
}
}


Well, the line giving me an error inaccessible

I had worked with java before and if i remember correctly i could extend it like that. But I'm not sure if I'm right (bad memory). Please response
Last edited on
Class inheritance is by default private. From within the Object class you can access the members of BasicNeed as with public inheritance, but from outside the class it is not visible that the class is derived from BasicNeed. That is why you can't access the BasicNeed member functions from Item.

If you want public inheritance (I'm sure you want), which is the only kind of inheritance in Java, you have to add public before the class name.
1
2
3
class Object : public BasicNeed
{
...
Last edited on
Topic archived. No new replies allowed.