I am trying to compile an android application in android studio (ndk r10d) which uses some C++ code. I needed C++11 so I added -std=gnu++11
(I need gnu++11
instead of c++11
for an extension I am using). I am using the stlport stl, due to other libraries I am using that use this stl library. So my cFlags and stl parameters in the build.gradle file looks like this:
stl "stlport_static" cFlags " mylib1.a mylib2.a ... -fexceptions -frtti -std=gnu++11"
I also have included memory: #include <memory>
When trying to compile I receive this error:
'shared_ptr' in namespace 'std' does not name a type
I have been using the boost implementation for the smart pointers till now but with the move to c++11 I would rather use the standard implementation.
A shared_ptr may share ownership of an object while storing a pointer to another object. get() returns the stored pointer, not the managed pointer.
shared_ptr is now part of the C++11 Standard, as std::shared_ptr . Starting with Boost release 1.53, shared_ptr can be used to hold a pointer to a dynamically allocated array. This is accomplished by using an array type ( T[] or T[N] ) as the template parameter.
If your C++ implementation supports C++11 (or at least the C++11 shared_ptr ), then std::shared_ptr will be defined in <memory> . If your C++ implementation supports the C++ TR1 library extensions, then std::tr1::shared_ptr will likely be in <memory> (Microsoft Visual C++) or <tr1/memory> (g++'s libstdc++).
The shared_ptr type is a smart pointer in the C++ standard library that is designed for scenarios in which more than one owner might have to manage the lifetime of the object in memory.
http://en.cppreference.com/w/cpp/memory/shared_ptr/make_shared use head file in your code.
#include <memory>
@T.C Looks like you were right. I saw your claim on a different question while looking for a solution for my problem, but as libraries that I am using are compiling with C++11 and STLport I thought that this claim might not be true.
What I think happened is that the libraries I'm using are not using any C++11 features that the STLport is missing. They are only using C++11 features that the gcc compiler supports. I need the gnuStl to support the features that I am using.
My solution was to use the boost implementation for the smart pointers and all other missing C++11 features.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With