English 中文(简体)
C++ 固定不变:共享——吸收使用和信息
原标题:C++ std::shared_ptr usage and information

我正试图使用<代码>std:共享_ptr。 我已经看到了关于这个问题的其他问题,但我仍在发现汇编错误。 我是否接受适当的资格和设置?

我做了些什么:

我试图将我的代码与两位标题分别汇编成册:<memory><tr1/memory>,但在这两种情况下仍然有以下错误。

我使用的缩略语版本是

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() );

我发现的错误如下:

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

象我这样看不出什么是正确的。 任何想法?

我知道,增强图书馆有<条码>共享_ptr,但这些图书馆目前不是我的选择。

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. 是否有任何关于 st点的有用文献?

最佳回答

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)

问题回答

你也要求参考或文献......

我发现3条可能有助于:

并对你的守则实例发表评论:

std::shared_ptr<A*> ptr_A = shared_ptr( new A() ); 

模板论点应当是A而不是A*:

std::shared_ptr<A> ptr_A = shared_ptr( new A() ); 

如果在座各位没有<代码>共享_ptr<>/code>,你可以加以利用。

#include <boost/shared_ptr.hpp>

boost::shared_ptr<A> ptr_A( new A() );




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签