Skip to content

Instantly share code, notes, and snippets.

@kuddai
Last active March 2, 2018 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuddai/78fb953d39fd857927e9f0afb2c1efaf to your computer and use it in GitHub Desktop.
Save kuddai/78fb953d39fd857927e9f0afb2c1efaf to your computer and use it in GitHub Desktop.
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