A
Alfred
Hi ti all!
I'd like o ask some clarification about this code.
I'd like to undestand why in main function pD->f() return D even if pE
and pD have the same value.
Do you know where I can find more information about?
Thank you very much!!!
Regards
Alfred
___________________________
#include <cstdlib>
#include <conio.h>
#include <iostream>
#include <windows.h>
using namespace std;
class B {
public:
void f() { cout << "B" << endl; };
};
class D : public B{
public: void f() { cout << "D" << endl; };
};
class E : public D {
public: void f() { cout << "E" << endl; };
};
int main()
{
E *pE = new E;
pE->f();
cout <<"pE= " << pE << endl;
D *pD = pE;
cout <<"pD= " << pD << endl;
pD->f();
system ("pause");
}
___________________________
I'd like o ask some clarification about this code.
I'd like to undestand why in main function pD->f() return D even if pE
and pD have the same value.
Do you know where I can find more information about?
Thank you very much!!!
Regards
Alfred
___________________________
#include <cstdlib>
#include <conio.h>
#include <iostream>
#include <windows.h>
using namespace std;
class B {
public:
void f() { cout << "B" << endl; };
};
class D : public B{
public: void f() { cout << "D" << endl; };
};
class E : public D {
public: void f() { cout << "E" << endl; };
};
int main()
{
E *pE = new E;
pE->f();
cout <<"pE= " << pE << endl;
D *pD = pE;
cout <<"pD= " << pD << endl;
pD->f();
system ("pause");
}
___________________________