使用c ++ 14遇到gcc问题。编译下面的代码时出现错误
"call of overloaded ‘make_unique(std::__cxx11::string)’ is ambiguous"
但是,如果我删除了make_unique的本地定义,我也会收到错误:
"‘make_unique’ was not declared in this scope"
似乎不可能得到这两个错误,因为std :: make_unique由于ADL而被拉入或者不是。这只是gcc的问题还是还有其他事情发生?
对于非模板std函数(例如stoi)的参考subbing make_unique,摆脱了“未在此范围内声明”错误,这使我认为这是gcc的一个问题。
#include <string>
#include <memory>
template <typename T, typename... Args>
inline std::unique_ptr<T> make_unique(Args&&... args)
{
return std::unique_ptr<T>( new T(std::forward<Args>(args)...) );
}
struct A
{
A(std::string a){ }
};
int main()
{
auto a = make_unique<A>(std::string());
}
答案 0 :(得分:4)
这不是一个错误。
没有您的本地模板定义,
make_unique<A>(std::string());
我们没有make_unique
的模板定义,我们有
(make_unique < A) > (std::string());
根据您的定义,我们有模板定义,因此,我们可以使用常规ADL。