Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If I want to use std::shared_ptr, which header to include? [duplicate]

Tags:

In c++0x shared_ptr will be moved from tr1 into std. So which header to include to get it?

I am using g++ 4.5 (ubuntu 10.10)

like image 342
BЈовић Avatar asked Apr 07 '11 19:04

BЈовић


People also ask

Can you copy shared_ptr?

After you initialize a shared_ptr you can copy it, pass it by value in function arguments, and assign it to other shared_ptr instances.

What library is shared_ptr in?

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++).

When should you use shared_ptr?

An object referenced by the contained raw pointer will not be destroyed until reference count is greater than zero i.e. until all copies of shared_ptr have been deleted. So, we should use shared_ptr when we want to assign one raw pointer to multiple owners. // referring to the same managed object.

What does shared_ptr get () do?

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.


1 Answers

You'll find it in <memory> now.

like image 101
Fred Foo Avatar answered Sep 30 '22 02:09

Fred Foo