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.

194 questions
0
votes
1 answer

Alternative library/template class for the deprecated auto_ptr in C++17

Have shared project library that has to be compiled with various compilers C++17 C++03 etc. So just using the better unique_ptr or the less than perfect auto_ptr as appropriate is not ideal if the code is to be kept common. Have look at the #ifdef…
Brian M
  • 1
  • 1
0
votes
0 answers

Returning auto_ptr has different results on diferent gcc versions

I have the following test code that I'm trying to run on QNX 6.5.0SP1 using gcc 4.4.2: // auto_ptr::operator= example #include #include #include std::auto_ptr source(void) { return…
JCowfer
  • 100
  • 9
0
votes
3 answers

Does using std::auto_ptr data members invoke UB?

As a followup to Class containing auto_ptr stored in vector, I believe the unstated conclusion there is that it is OK to use classes with an auto_ptr member as container elements, so long as both copy construction and copy assignment are…
Tabber33
  • 515
  • 3
  • 11
0
votes
1 answer

My Auto Pointer works even after ownership transfer

As far as I know, auto_ptr works on the concept of transfer of ownership. Also, once an auto pointer transfer its ownership to another auto pointer, it should not be able refer to the object it points to anymore. However, this is not the case I…
0
votes
0 answers

C++:Can`t access protected members with auto_ptr

Why am i not able to get access to protected members of myclass when i am using auto_ptr ? auto_ptr aptr_myclass( new myclass ); aptr_peercfg->name=func(_name); aptr_peercfg->lastname=func(_lastname); class myclass{ protected: …
Krcn U
  • 361
  • 7
  • 16
0
votes
0 answers

when constructor throws an error, auto_ptr does not destruct object

I know auto_ptr destruct object automatically when it is out of scope. But when Constructor throws exception, it does not destruct object(take a look at below code snippet). Let me explain below code , I have class A which has an auto_ptr field…
siva
  • 1,443
  • 1
  • 18
  • 26
0
votes
3 answers

C++ auto_ptr and copy construction

If I have a class template struct C { ... private: auto_ptr ptr; }; How do I define the copy constructor for C: It cannot be template C::C(const C& other) because I want to if I copy the auto_ptr from other,…
user231536
  • 2,471
  • 4
  • 28
  • 43
0
votes
1 answer

No instance of constructor --- Matches Argument List (Templating issue maybe)

I am currently trying to write a basic wrapper for the cml (http://www.cmldev.net/) math library for a project I am working on. I have a wrapper for the cml vector class which has one private member #ifndef VECTOR3_H_ #define VECTOR3_H_ #include…
Craig
  • 1,109
  • 1
  • 13
  • 26
0
votes
1 answer

Can't inherit from auto_ptr without problems

What I want to do is this: #include class autostr : public std::auto_ptr { public: autostr(char *a) : std::auto_ptr(a) {} autostr(autostr &a) : std::auto_ptr(a) {} // define a bunch of string utils…
fret
  • 1,478
  • 18
  • 35
0
votes
1 answer

What is the size of an auto_ptr?

Does an auto_ptr have the same size as a pointer? I have to substitute it with a boost::scoped_ptr, and I was wondering if these two data types have the same size.
Pietro
  • 10,628
  • 22
  • 80
  • 165
0
votes
2 answers

Normal pointer vs Auto pointer (std::auto_ptr)

Code snippet (normal pointer) int *pi = new int; int i = 90; pi = &i; int k = *pi + 10; cout< pi(new int); int i = 90; pi = &i; int k = *pi + 10; //Throws…
Akaanthan Ccoder
  • 1,941
  • 3
  • 20
  • 36
0
votes
2 answers

Creating an auto_ptr with 2 arguments

Hi I have a compile error when I run this code: std::auto_ptr m_display = std::auto_ptr(new MyDisplay(this, m_displayController)); The error is this one: error C2664: 'MyDisplay::MyDisplay(DemoWindow…
Carlos Vargas
  • 229
  • 6
  • 18
0
votes
6 answers

How does c++ auto_ptr relate to managed pointers (Java, C#...)

I come from a managed world and c++ automatic memory management is quite unclear to me If I understand correctly, I encapsulate a pointer within a stack object and when auto_ptr becomes out of scope, it automatically calls delete on the pointed…
Eric
  • 18,532
  • 17
  • 78
  • 138
0
votes
1 answer

tagpy: auto_ptr in python?

I'm not a professional, I'm just frustrated that almost no linux audio players support the id3v2 composer tag, and I'd like to figure out how to add it. Taglib doesn't support the composer tag directly, but there is a workaround by building the tag…
0
votes
3 answers

How to access the object pointed to by a std::auto_ptr

In my TicTacToe game I having some trouble with virtual functions. The following code throws an error in Dev C++: "class std::auto_ptr' has no member named 'makeAMove'. According to the error, the problem has something to do with the makeAMove…
navig8tr
  • 1,442
  • 5
  • 20
  • 49
1 2 3
12
13