Inheritance


1
2
3
4
5
6
7
8
9
//Big.h
class Big{
private: 
int k;
public:
//....
....

};


1
2
3
4
5
6
7
8
// Small.h
class Small: public Big
{
public:
......
.....

};


In class Small, how can i use private ink k of class Big???if i have class Small: public Big

Thanks in advance!!!
how can i use private ink k of class Big
You cannot. The meaning of private is no one aside from original class and its friends can use private parts. If you want to make them usable in derived classes you need to make them at least protected. Usually you should not have the need to directly manipulate data of base class in derived.
thks, but in my exercises

k is private
Can you add accessor functions to the base class?

1
2
3
4
5
...
protected:
    int getK();
    void setK(int newK);
...


If the data member of a base class is private and there are no accessor functions that are protected or public, only the base class has access to the data member.
Topic archived. No new replies allowed.