Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <memory>
- #include <iostream>
- struct Foo
- {
- int* arr;
- size_t size;
- Foo(int* arr, size_t size) :
- arr(arr), size(size)
- {
- }
- Foo(Foo const& other) :
- arr(new int[other.size]),
- size(other.size)
- {
- std::copy(other.arr, other.arr + size, arr);
- std::cout << "I'm copy constructor!\n";
- }
- ~Foo()
- {
- delete[] arr;
- std::cout << "I'm destructor!\n";
- }
- void Print()
- {
- std::cout << "\n";
- for (size_t i = 0; i < size; i++)
- std::cout << arr[i] << " ";
- }
- };
- Foo bar()
- {
- Foo res(new int[150], 150);
- for (size_t i = 0; i < 150; i++)
- res.arr[i] = rand() % 15;
- return res;
- }
- int main()
- {
- Foo x = bar();
- x.Print();
- std::cin.ignore();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement