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
0
votes
1 answer

unique_ptr/auto_ptr look alike with custom deleter for c++98

auto_ptr doesn't support custom deleter and tr1 shared_ptr is not a good option for me. Are there any good options before c11 for unique_ptr/ auto_ptr look alike with custom deleter?
0
votes
3 answers

Pass pointer to auto_ptr with C++

i have a function that does this: static MyClass* MyFunction(myparams) { return new MyClass(myparams) } and i would be able to call this function inside another one that has the following signature: void MyFunction2(std::auto_ptr
Stefano
  • 3,213
  • 9
  • 60
  • 101
0
votes
0 answers

initializing functions as auto_ptr with class reference

I'm trying to understand the flow of a code and I came across this code snippet in the header file typedef std::auto_ptr auto_ptr_t; static Client::auto_ptr_t open(const std::string& uri, const std::string& user, const std::string&…
Abhay Nayak
  • 1,069
  • 1
  • 11
  • 25
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
  • 130
  • 1
  • 11
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
  • 535
  • 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…
pabitra mohan
  • 77
  • 1
  • 5
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
  • 411
  • 1
  • 9
  • 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,693
  • 2
  • 21
  • 29
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,661
  • 4
  • 33
  • 45
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,199
  • 1
  • 13
  • 27
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,542
  • 21
  • 36
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
  • 12,086
  • 26
  • 100
  • 193
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
  • 2,159
  • 5
  • 21
  • 37
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
  • 254
  • 6
  • 18