M
MJ
Hi
I have a following sample code
class base and class derived.
I have inherited the base class as private and tried to compile the
code its giving an error
"conversion from 'class derived *' to 'class base *' exists, but is
inaccessible"
If I inherit using public it works well ...
I am not very clear about the private inheritance
I will be happy if someone can guide me ... when shall I use public,
private and protected inheritance
-------------------------------------------------------
#include<iostream>
using namespace std;
class base{
public:
int b;
virtual f(){ cout << " base" << endl;}
};
class derivedrivate base{
public:
int d;
f()
{
cout << " derived" << endl;
}
};
int main () {
derived *d = new derived;
d->f();
base *b;
b = d;
int a;
cin >> a;
return 0 ;
}
I have a following sample code
class base and class derived.
I have inherited the base class as private and tried to compile the
code its giving an error
"conversion from 'class derived *' to 'class base *' exists, but is
inaccessible"
If I inherit using public it works well ...
I am not very clear about the private inheritance
I will be happy if someone can guide me ... when shall I use public,
private and protected inheritance
-------------------------------------------------------
#include<iostream>
using namespace std;
class base{
public:
int b;
virtual f(){ cout << " base" << endl;}
};
class derivedrivate base{
public:
int d;
f()
{
cout << " derived" << endl;
}
};
int main () {
derived *d = new derived;
d->f();
base *b;
b = d;
int a;
cin >> a;
return 0 ;
}