Last active
August 13, 2016 07:51
-
-
Save itayB/77a358bdaa0ba56f8599700b80542f66 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
class A | |
{ | |
public: | |
A() { printf("A\n"); } | |
~A() { printf("~A\n"); } | |
void p1() { printf("p1A\n"); } | |
virtual void p2() { printf("p2A\n"); } | |
}; | |
class B : public A | |
{ | |
public: | |
B() { printf("B\n"); } | |
~B() { printf("~B\n"); } | |
void p1() { printf("p1B\n"); } | |
void p2() { printf("p2B\n"); } | |
}; | |
class C : public A | |
{ | |
public: | |
C() { printf("C\n"); } | |
virtual ~C() { printf("~C\n"); } | |
void p1() { printf("p1C\n"); } | |
void p2() { printf("p2C\n"); } | |
}; | |
class D : public C | |
{ | |
public: | |
D() { printf("D\n"); } | |
~D() { printf("~D\n"); } | |
}; | |
B b; | |
int main() | |
{ | |
C* pc = new D; | |
A* pa1 = pc; | |
A* pa2 = &b; | |
pa1->p1(); | |
pa1->p2(); | |
pa2->p1(); | |
pa2->p2(); | |
D d; | |
d.p1(); | |
d.p2(); | |
delete pa1; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment