Could someone please explain how to resolve the ambigious overload warning for make_unique, where the error comes from and what it does exactly mean (I do understand what an ambigious overload is but I am unsure why I get one for this particular code)? I am using c++11, therefore I use the recommended template from Herb Sutter.
Using it I get the following error:
Error 4 error C2668: 'make_unique' : ambiguous call to overloaded function
And the hover over tooltip in visual studio 13 gives me the following to methods:
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
The second one should be the one called from the make_unique template
/* 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)...));
}
The constructor to be forwarded to:
Shader(const std::string& name);
The code generating the error
std::string _name = "Shader";
std::unique_ptr<Shader> s = make_unique<Shader>(_name);
The call is ambiguous because you do have std::make_unique
, as shown by the tooltip contents you quote. And even though you did not write std::
, since you are passing a std::string
argument-dependent lookup kicks in to search that namespace automatically.
When you say "I am using C++11", that's not quite right, because Visual Studio doesn't let you choose which standard to write in. It just provides you with the latest support it has mustered for any given feature. And, apparently, Visual Studio 2013 has C++14's std::make_unique
.
Remove yours.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With