Questions tagged [auto-ptr]

A C++ template class that provides a limited garbage collection facility for pointers, by allowing pointers to have the elements they point to automatically destroyed when the auto_ptr object is itself destroyed. Deprecated as of C++11 in favor of unique_ptr.

auto_ptr is deprecated as of C++11. For the C++11 equivalent, unique_ptr, see the reference page.

Reference page for auto_ptr.

197 questions
1
vote
3 answers

unique_ptr behaviour while passing through function

In below code snippet i am getting segmentation fault while passing unique_ptr as as value. usually this is known issue with auto_ptr as due to ownership issue (Assignee pointer becomes NULL) it can't be accessed after assignment. but why i am…
user2997518
  • 812
  • 6
  • 17
1
vote
3 answers

"using" (or other mechanism) to swap in unique_ptr for auto_ptr in C++11?

I'm catching a compile warning under Cygwin with -std=c++11: cryptlib.cpp: In member function ‘virtual size_t PK_Signer::SignMessage(RandomNumberGenerator&, const byte*, size_t, byte*) const’: cryptlib.cpp:770:41: warning: ‘auto_ptr’ is deprecated…
jww
  • 97,681
  • 90
  • 411
  • 885
1
vote
2 answers

Why an auto_ptr can "seal" a container

auto_ptr on wikipedia said that "an auto_ptr containing an STL container may be used to prevent further modification of the container.". It used the following example: auto_ptr > open_vec(new…
icephere
  • 1,415
  • 2
  • 9
  • 5
1
vote
2 answers

Why a unique_ptr can be used with std containers, vectors<> for example?

I understand that auto_ptr cannot be used with vectors since auto_ptr does not meet the requirement of being a copy constructible. Since the auto_ptr being copied is modified, copying does not result in two exact copies thereby violating the copy…
Vishal
  • 158
  • 6
1
vote
1 answer

How to use auto_ptr in this case

I have the following code: void do_something(Image *image) { Image *smoothed = NULL; Image *processed = NULL; if (condition_met) { smoothed = smooth(image); processed = smoothed; } else { processed =…
Luca
  • 10,458
  • 24
  • 107
  • 234
1
vote
1 answer

Why it's can be compiled in GNU/C++, can't compiled in VC++2010 RTM?

#include #include #include #include "copy_of_auto_ptr.h" #ifdef _MSC_VER #pragma message("#include ") #include //…
Eric Kung
  • 43
  • 1
  • 1
  • 10
1
vote
1 answer

Class is freed instantly after it's put into unique_ptr

I working currenly on server using Poco Net & Reactor Pattern. I watned to do class CSConnection unique_ptr because class objects are referenced to worker thread pool. Constructor : CSConnection::CSConnection(StreamSocket& socket, SocketReactor&…
1
vote
1 answer

Storing pointers owned by auto_ptr's in a vector causing a crash

I am having difficulty with a crash using an auto_ptr. I am aware that you cannot store auto_ptr's in STL containers. But what about storing pointer values held by the auto_ptr inside a vector? If the auto_ptr's delete the stored object they…
AdamDH
  • 13
  • 3
1
vote
2 answers

Sequencing of the copying when passing by value in C++

In C++, when passing an object by value, are there restrictions on when the copy takes place ? I have the following code (simplified): class A; class Parent { public: void doSomething(std::auto_ptr a); // meant to transfer…
J.N.
  • 8,203
  • 3
  • 29
  • 39
1
vote
6 answers

Making a non-object resource RAII-compliant

in my code I use HANDLEs from windows.h. They are used like HANDLE h; if (!openHandleToSomething(arg1, arg2, &h)) { throw std::exception("openHandleToSomething error"); } /* Use the handle in other functions which can throw as well */ if…
Etan
  • 17,014
  • 17
  • 89
  • 148
1
vote
4 answers

smart pointer in the std::map

I've defined a class myClass,one of its data members is std::map dataMap data is defined as struct data { int d1; int d2; std::string d3; } Inserting of data to the dataMap is done as follows :dataMap[key] = new data; the…
YAKOVM
  • 9,805
  • 31
  • 116
  • 217
1
vote
1 answer

Relinquish ownership of auto_ptr contained object

I have a class that constructs an auto_ptr and gets the T object data filled by a utility function. However, I want the T object stored by an object manager that will persist the whole life of the application. The question is - once I have…
Steztric
  • 2,832
  • 2
  • 24
  • 43
1
vote
4 answers

How to effectively delete C++ objects stored in multiple containers? auto_ptr?

I have an application which creates objects of a certain kind (let's say, of "Foo" class) during execution, to track some statistics, and insert them into one or both of two STL maps, say: map map1; map map2; I was wondering…
puccio
  • 3,054
  • 8
  • 29
  • 20
1
vote
1 answer

Assigning raw pointers to auto_ptr

I was reading an article about effectively using auto_ptr. In there, the following code was suggested as a correct piece of code: // Example 10(c): Correct (finally!) // auto_ptr f() { auto_ptr result = new String; *result =…
B Faley
  • 17,120
  • 43
  • 133
  • 223
1
vote
1 answer

Debug Assertion Failed When I Delete A SDL_VideoInfo Pointer

I'm making a game in SDL, and I'm using SDL_VideoInfo to get the monitors current resolution. Example Code: (This may have a few spelling mistakes or wrong names for functions/variable types, i'm writing this right now off my memory). #include…
Name
  • 2,037
  • 3
  • 19
  • 28