【发布时间】:2015-02-15 00:28:51
【问题描述】:
有人可以解释如何解决 make_unique 的模棱两可的过载警告,错误来自哪里以及它的确切含义(我确实了解模棱两可的过载是什么,但我不确定为什么我会为这个特定的代码得到一个) ?我使用的是 c++11,因此我使用 Herb Sutter 推荐的模板。
使用它我得到以下错误:
Error 4 error C2668: 'make_unique' : ambiguous call to overloaded function
Visual Studio 13 中的鼠标悬停在工具提示上为我提供了以下方法:
function template "std::enable_if<!std::is_array<_Ty>::value, std::unique_ptr<_Ty,std::default_delete<_Ty>>>::type std::make_unique<_Ty,_Types...>(_Types &&..._Args)"
function template "std::unique_ptr<T, std::default_delete<T>> make_unique<T,Args...>(Args...)
argument types are: std::string
第二个应该是从 make_unique 模板调用的那个
/* Will be part of c++14 and is just an oversight in c++11
* From: http://herbsutter.com/gotw/_102/
*/
template<typename T, typename ...Args>
std::unique_ptr<T> make_unique(Args&& ...args){
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
要转发到的构造函数:
Shader(const std::string& name);
产生错误的代码
std::string _name = "Shader";
std::unique_ptr<Shader> s = make_unique<Shader>(_name);
【问题讨论】: