2017-03-25 32 views

回答

3

因爲unique_ptr沒有爲其operator=「分配原始指針」功能。
這是可能是,以避免人們犯錯誤。

(順便說一句,你std::move什麼也不做。)

您可以使用構造:

std::unique_ptr<int> pi(new int); 

std::make_unique

auto pi = std::make_unique<int>(); 

或者,到後來分配,reset()

std::unique_ptr<int> pi; 
pi.reset(new int); 
相關問題