22

我正在尝试在使用一些 C++ 代码的 android studio (ndk r10d) 中编译一个 android 应用程序。我需要 C++11,所以我添加了-std=gnu++11(我需要gnu++11而不是c++11我正在使用的扩展)。我正在使用 stlport stl,因为我使用的其他库使用了这个 stl 库。所以我在 build.gradle 文件中的 cFlags 和 stl 参数看起来像这样:

stl "stlport_static"
cFlags " mylib1.a mylib2.a ... -fexceptions -frtti -std=gnu++11"

我还包括内存:#include <memory>

尝试编译时收到此错误:

'shared_ptr' in namespace 'std' does not name a type

到目前为止,我一直在使用智能指针的 boost 实现,但是随着迁移到 c++11,我宁愿使用标准实现。

4

3 回答 3

36

http://en.cppreference.com/w/cpp/memory/shared_ptr/make_shared 在您的代码中使用头文件。

#include <memory>
于 2015-12-03T08:52:38.987 回答
2

@TC 看起来你是对的。在为我的问题寻找解决方案时,我看到了您对另一个问题的主张,但是由于我正在使用的库是用 C++11 和 STLport 编译的,所以我认为这种主张可能不正确。

我认为发生的事情是我正在使用的库没有使用 STLport 缺少的任何 C++11 功能。他们只使用 gcc 编译器支持的 C++11 功能。我需要 gnuStl 来支持我正在使用的功能。

我的解决方案是对智能指针和所有其他缺少的 C++11 功能使用 boost 实现。

于 2015-03-19T09:41:12.403 回答
1

I got here googling for a similar error, but the answer did not work:

error: ‘shared_pointer’ in namespace ‘std’ does not name a template type

In my case, it was a typo:

std::shared_pointer

should be

std::shared_ptr
于 2018-09-28T11:42:41.243 回答