#include #include #include #include using namespace std; class FooT{ public: FooT(int n): number{n}{ cout << n << endl; } int Value() const{ return number; } private: int number; }; const int SIZE = 10; int main() { unique_ptr foo; unique_ptr boo; if (foo == nullptr) { cout << "foo is null" << endl; } foo = make_unique(3); cout << " The number is " << foo->Value() << endl; cout << "Foo points at " << foo.get() << endl; boo = move(foo); if (foo == nullptr) { cout << "foo is null" << endl; } cout << "After the move" << endl; cout << "Foo points at " << foo.get() << endl; cout << "Boo points at " << boo.get() << endl; cout << " The number is " << boo->Value() << endl; cout << endl << endl << endl; // an example of just a pointer. unique_ptr word; word = make_unique("Hello World"); word = make_unique(); *word = "Hello To You"; cout << "the word is " << *word << endl; cout << "The size of the word is " << word->size() << endl; cout << endl; // an array example unique_ptr ints = make_unique(SIZE); int i = 0; for(auto x : {1,2,3,4,5,6,7,8,9,10}) { ints[i++] = x; } for(i=SIZE-1; i > 0; i--) { cout < otherWord; cout << "Before the move " << endl; cout << " The address of word " << word.get() << endl; cout << " The address of otherword " << otherWord.get() << endl; //otherWord = word; otherWord = move(word); cout << "After the move " << endl; cout << " The address of word " << word.get() << endl; cout << " The address of otherword " << otherWord.get() << endl; return 0; }