请问如何解决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);
#if
块内(如果你能找出用于它的宏),以便你的代码准备好被移植到其他编译器。但除此之外,不行。 - Lightness Races in Orbitmake_unique
是一个模板名称,因此无法解析<
。http://coliru.stacked-crooked.com/a/33fc5b4228e53f63 - T.C.