Last active
March 2, 2018 20:44
-
-
Save kuddai/78fb953d39fd857927e9f0afb2c1efaf 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
class A { | |
public: | |
A(int j) {i=new int[j];} | |
virtual ~A() {delete[] i;} | |
private: | |
int* i; | |
}; | |
class B : public A { | |
public: | |
B(int j):A(j) {i = new char[j];} | |
~B() {delete[] i;} | |
private: | |
char* i; | |
}; | |
int main() { | |
A *a = new A(10); | |
B *b = new B(20); | |
delete a; | |
a = b; | |
delete b; | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment