比起直接使用new,更偏心使用std::make_unique和std::make_shared

std::make_shared是C++11的一部分,std::make_unique不是,它在C++14才歸入標準庫。若是你使用的是C++11,不用憂傷,由於std::make_unique的簡單版本很容易寫出來:數組 template<typename T, typename... Ts> std::unique_ptr<T> make_unique(Ts&&... params) {
相關文章
相關標籤/搜索