Created
February 8, 2019 15:23
-
-
Save dermesser/fcebac925ca994b4e73e70bab961f070 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <iostream> | |
#include <cstdlib> | |
struct A { | |
int i; | |
A(int i) : i(i) {} | |
~A() { std::cout << i - 1; } | |
void print() { std::cout << i; } | |
}; | |
class B { | |
A* a; | |
public: | |
B(A* a) : a(a) {} | |
~B() { delete a; } | |
void print() { std::cout << a->i; } | |
}; | |
int main(int argc, char** v) { | |
for (int i = 0; i < argc; i++) { | |
B* b = new B(new A(i+std::atoi(v[1]))); | |
b->print(); | |
delete b; | |
} | |
std::cout << "\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment