c++ - enable_shared_from_this 不适用于 xcode 5

标签 c++ xcode c++11 clang llvm

#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/

相关文章:

java - 将 C++ 项目导出到 Android - JNI/JavaCPP/Visualgdb

c++ - 在方法中注入(inject)额外数据

c++ - 复制构造函数会在这里工作吗?

xcode - 编写 Bridge 和 Apple Mail 脚本

xcode - 有没有办法在Xcode 5或Xcode 6中更改xcassets View 的背景颜色?

c++ - 特征向量对数错误不完整类型的使用无效

c++ - 如何禁用 QTextEdit 中的光标?

xcode - 平移 AudioKit 的 AKMetronome

c++ - 跨线程调用 a.k.a 从其他线程在主/UI 线程上运行而无需依赖

c++ - 在 C++11 中解析毫秒日期时间的最佳方法是什么