Created
June 19, 2014 01:28
-
-
Save mitsu-ksgr/771c475fd38bd3123238 to your computer and use it in GitHub Desktop.
C++11 std::unique_ptrに配列を持たせるテスト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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