Skip to content

Instantly share code, notes, and snippets.

@mitsu-ksgr
Created June 19, 2014 01:28
Show Gist options
  • Save mitsu-ksgr/771c475fd38bd3123238 to your computer and use it in GitHub Desktop.
Save mitsu-ksgr/771c475fd38bd3123238 to your computer and use it in GitHub Desktop.
C++11 std::unique_ptrに配列を持たせるテスト
#include <iostream>
#include <memory>
struct Item {
public:
Item() {
std::cout << "Item::Constructor" << std::endl;
}
~Item() {
std::cout << "Item::Destructor" << std::endl;
}
};
class Test {
public:
Test() {
std::cout << "Test::Constructor" << std::endl;
this->mArray = std::unique_ptr<Item[]>(new Item[3]);
}
~Test() {
std::cout << "Test::Destructor" << std::endl;
}
protected:
std::unique_ptr<Item[]> mArray;
};
int main()
{
Test test;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment