C++ std::shared_ptr usage and information(C++ std::shared_ptr 用法和信息)
问题描述
I am trying to use std::shared_ptr
in my code. I have seen there have been other questions on the subject, but I am still getting a compiler error. Have I got the right version of gcc and setup?
What I have done:
I have tried to compile my code with both headers separately — <memory>
and <tr1/memory>
but still get the errors below in both cases.
The version of gcc I am using is
gcc --version
gcc (GCC) 4.3.2
When I include <memory>
header I use std::shared_ptr
and with the <tr1/memory>
header I use std::tr1::shared_ptr
? Is this correct?
I have set up the shared_ptr as follows:
std::shared_ptr<A*> ptr_A = shared_ptr( new A() );
The error I get is as follows:
src/WH.cxx:156: error: 'shared_ptr' is not a member of 'std'
src/WH.cxx:162: error: 'shared_ptr' was not declared in this scope
when I try the <tr1/memory>
header
src/WH.cxx:156: error: 'std::tr1' has not been declared
src/WH.cxx:162: error: 'shared_ptr' was not declared in this scope
Looks like I am not including something correctly. Any ideas?
I know the boost library has shared_ptr
but these libraries are not an option for me at the moment.
EDIT: Just to add, my compiler options are as follows: g++ -O3 -g3 -m32 -fPIC -Wno-deprecated -pthread -m32 Am I missing anything?
P.S. Is there any useful literature on the std smart pointers?
std::tr1::shared_ptr
is part of the TR1 additions to the C++ STL.
With GCC, it is available either through #include <tr1/memory>
(GCC 4.1) or #include <memory>
(GCC 4.3)
这篇关于C++ std::shared_ptr 用法和信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C++ std::shared_ptr 用法和信息
基础教程推荐
- 调用std::Package_TASK::Get_Future()时可能出现争用情况 2022-12-17
- 运算符重载的基本规则和习语是什么? 2022-10-31
- 如何在 C++ 中处理或避免堆栈溢出 2022-01-01
- 设计字符串本地化的最佳方法 2022-01-01
- C++ 标准:取消引用 NULL 指针以获取引用? 2021-01-01
- C++ 程序在执行 std::string 分配时总是崩溃 2022-01-01
- 什么是T&&(双与号)在 C++11 中是什么意思? 2022-11-04
- 您如何将 CreateThread 用于属于类成员的函数? 2021-01-01
- 如何定义双括号/双迭代器运算符,类似于向量的向量? 2022-01-01
- C++,'if' 表达式中的变量声明 2021-01-01