Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

enable_shared_from_this not working on xcode 5

#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;
}

When i try to compile this on Xcode 5 i get

Use of undeclared identifier 'shared_from_this'

I tested it and its working on Visual Studio 2010.

like image 441
ali_nakipoglu Avatar asked May 05 '14 17:05

ali_nakipoglu


1 Answers

    return this->shared_from_this();
           ^^^^^^

VC++ 2010 does not implement the lookup rules for templated base classes exactly correctly. The clang behavior is correct. The above fix will make it work on both your platforms.

like image 193
Howard Hinnant Avatar answered Sep 20 '22 19:09

Howard Hinnant