Skip to content

Instantly share code, notes, and snippets.

@b4284
Created September 21, 2017 22:41
Show Gist options
  • Select an option

  • Save b4284/baf0679ee9dd06be5182f7a9c859fadc to your computer and use it in GitHub Desktop.

Select an option

Save b4284/baf0679ee9dd06be5182f7a9c859fadc to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <memory>
class A {
public:
A() {}
A(int i) {
std::cout << i << std::endl;
}
virtual ~A() {
std::cout << "A DIE" << std::endl;
}
};
class B : public A {
public:
B(const char *s) {
std::cout << s << std::endl;
}
~B() {
std::cout << "B DIE" << std::endl;
}
};
int main() {
std::vector<std::unique_ptr<A>> av;
av.push_back(std::move(std::unique_ptr<A>(new B("GOING INTO B"))));
av.push_back(std::move(std::unique_ptr<A>(new A(5))));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment