Enable_shared_from_this在xcode 5上不起作用

enable_shared_from_this not working on xcode 5

本文关键字:不起作用 xcode this shared from Enable      更新时间:2023-10-16
#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没有完全正确地实现模板基类的查找规则。叮当的行为是正确的。上面的修复将使它在您的两个平台上工作。