Skip to content

Instantly share code, notes, and snippets.

@dermesser
Created February 8, 2019 15:23
Show Gist options
  • Save dermesser/fcebac925ca994b4e73e70bab961f070 to your computer and use it in GitHub Desktop.
Save dermesser/fcebac925ca994b4e73e70bab961f070 to your computer and use it in GitHub Desktop.
#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