【发布时间】:2014-06-22 02:39:33
【问题描述】:
#include <iostream>
#include <memory>
template<typename T>
class Test: public std::enable_shared_from_this< Test<T> >
{
public:
std::shared_ptr< Test<T> > getMe()
{
return shared_from_this();
};
};
int main(int argc, const char * argv[])
{
Test<int> aTest;
return 0;
}
当我尝试在 Xcode 5 上编译它时,我得到了
Use of undeclared identifier 'shared_from_this'
我在 Visual Studio 2010 上对其进行了测试。
【问题讨论】:
-
你忘了用
std::来限定它,就像std::shared_from_this()。 -
这里没有 std 命名空间,只需要从 enable_shared_from_this 扩展并返回 getMe 函数的类型,并且它们已经输入。
-
加上 shared_from_this 是 enable_shared_from_this 类的成员函数。你确定你正在阅读这个问题吗?
标签: c++ xcode c++11 clang llvm