|
-
July 22nd, 2007, 12:22 AM
#1
C++ Private Inheritance
Hi Experts,
If I have a class derived from the base class using private keyword(private inheritance), then what are the members of the base class I can access from the derived class.
I read from a book that incase of private inheritance all the data members of the base class become private in the derived class. if above is true then following code should not compile.
#include <iostream>
using namespace std;
class Base {
public:
int j;
void display1() {
cout << "Value of i = " << i << endl;
}
private:
int i;
protected:
int k;
};
class Derived_public: private Base {
public:
void display() {
display1();
cout << "Derived_public: protected data = " << k << endl;
cout << "Derived_public: public data = " << j << endl;
}
};
int main() {
Derived_public d1;
d1.display();
return 0;
}
+++++++++++++++++++++++++++++++++++++
But the above code compiles and I can access public and protected data members of base class.
Is this the normal behaviour..Please help..
Thanks and Regards,
Paresh
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|