我有以下类定义:
class Portal
{
public:
Portal( const vector<vec3> &vertices, shared_ptr<Sector> target );
...
};
在其他地方,我想像这样创建一个所述类的实例:
auto portal = make_shared<Portal>( portalVertices, target );
但是,我在 Visual Studio 2010 中收到以下错误消息:
error C2668: 'boost::make_shared' : ambiguous call to overloaded function
谁能告诉我为什么?我只定义了一个构造函数。谢谢!
最佳答案
当您使用关键字 auto 时,我假设您使用的是 C++11 功能。
C++11 还附带了 std::make_shared
。
所以,请尝试添加命名空间:
auto portal = std::make_shared<Portal>( portalVertices, target );
或
auto portal = boost::make_shared<Portal>( portalVertices, target );
所以我通常在我的代码/.C 文件中做的是:
using namespace std; // this is a "using" directive
....
void somefunction() {
auto portal = make_shared<Portal>( ... );
}
正如您提到的,您在 header 中指定了
using boost::make_shared;
我真的很想看看完整的头文件。正如我认为您实际上想要一个 using 指令,但最终得到了一个 using 声明。
看看这个描述:
使用
指令:http://msdn.microsoft.com/en-us/library/aewtdfs3%28v=vs.80%29.aspx
使用
声明:http://msdn.microsoft.com/en-us/library/was37tzw%28v=vs.80%29.aspx
关于c++ - 'boost::make_shared':对重载函数的模糊调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8356618/