Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <memory>
- #include <iostream>
- using namespace std;
- class Foo{
- public:
- Foo(int k)
- : k1(k)
- , k2(k){
- }
- Foo(const Foo& foo)
- : k1(foo.k1){
- std::cout << foo.foo->k1 << " " << foo.foo->k2 << "\n";
- k2 = foo.k2;
- }
- void set_other(const shared_ptr<Foo>& other){
- foo = other;
- }
- private:
- int k1, k2;
- shared_ptr<Foo> foo;
- };
- int main(){
- shared_ptr<Foo> a = make_shared<Foo>(1);
- shared_ptr<Foo> b = make_shared<Foo>(2);
- b->set_other(a);
- *a = *b;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement