#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 上运行。
最佳答案
return this->shared_from_this();
^^^^^^
VC++ 2010 没有完全正确地实现模板化基类的查找规则。 clang 行为是正确的。上述修复将使其适用于您的两个平台。
关于c++ - enable_shared_from_this 不适用于 xcode 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23478503/