shared_ptr of a template class using gcc 4.6
shared_ptr of a template class using gcc 4.6
试图在c++11 中实现以下功能
template< class A >
class B{
std::shared_ptr< A > a_shared_ptr;
};
B< int > b;
有可能吗?
正在获取以下错误
..//src/threading/note.h:26:错误:ISO C++禁止声明没有类型的"shared_ptr"../../src/threading/note.h:26:错误:"::"的使用无效../../src/threading/note.h:26:错误:应为";"在'<'之前令牌
是的,这是可能的
由于std::shared_ptr
是C++11的一个新特性,您必须在编译器上启用对C++11的支持。在GCC下,选项为:-std=c++0x
或-std=gnu++0x
。
如果我不启用这些功能,我会得到与您完全相同的错误。
另一点是:不要忘记包括std::shared_ptr
:的标题
#include <memory>
只需包含std::shared_ptr的头,它就可以很好地编译:
#include <memory>
template< class A >
class B{
std::shared_ptr< A > a_shared_ptr;
};
int main()
{
B< int > b;
return 0;
}
相关文章:
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 奇怪的结构&GCC&clang(void*返回类型)
- GCC本机矩阵运算库
- PowerPC ppc64le上的Gcc Woverloaded虚拟错误
- gcc和c++17的过载解析失败
- 数据成员SFINAE的C++17测试:gcc vs clang
- GCC对可能有效的代码抛出init list生存期警告
- 如何解决gcc编译器优化导致的centos双编译器设置中的分段错误
- 使用 GCC 卸载的 OpenMP 卸载失败,并出现"Ptx assembly aborted due to errors"
- 为什么与常规GCC不同,即使有"学究性错误",MinGW-GCC也能容忍丢失的返回类型
- 使用gcc从静态链接的文件中查找可选符号
- 普通环路未使用gcc 4.8.5自动矢量化
- 有了gcc,是否可以链接库,但前提是它存在
- "using namespace std;"在C++的作用是什么?
- 在clang++预处理器中确定gcc工具链版本
- 为什么 gcc 编译这个而 msvc 没有
- 为什么lambda在clang上崩溃而不是在gcc上崩溃
- gcc/g++ using linkerflag "-lSDL2"
- shared_ptr of a template class using gcc 4.6
- 'using' gcc 中的关键字