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
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
  • 19,525
  • 19
  • 84
  • 147
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,724
  • 8
  • 31
  • 69
0
votes
3 answers

std::auto_ptr becomes invalid after being passed to a function by value

I've got the following sample code: #include #include class A { public: A(){ std::cout << "A ctor" << std::endl;} ~A() {std::cout << "A dtor" << std::endl;} void bar(){std::cout << "bar()" << std::endl;} }; void…
B Faley
  • 17,120
  • 43
  • 133
  • 223
0
votes
2 answers

Constructor taking an auto_ptr

I want to write a C++ class with a constructor which takes an auto_ptr as its argument so that I could initialize class instances from auto_ptrs to another instance: #include class A { public: A() {} A(std::auto_ptr other)…
cfh
  • 4,576
  • 1
  • 24
  • 34
0
votes
0 answers

Template auto-generated code, not a type

I'm attempting to generate a class than can read any type of serialized XSD/XML code. Since I have about 1000 different data defintions, I would love to make the XmlLoader class generic. However, in the auto-generated serialized code, the way to…
Tyler Jandreau
  • 4,245
  • 1
  • 22
  • 47
0
votes
1 answer

Auto_ptr to external C struct

I would like to create an Auto_Ptr to a legacy C struct; I only have header files and static libraries so I cannot modify the source code. I wondered wouldn't the auto_ptr automatically try to call the Destructor ~foo() if I call p.release() or…
Matthias Hueser
  • 255
  • 1
  • 3
  • 11
0
votes
1 answer

std::auto_ptr vs. std::tr1::shared_ptr

Possible Duplicate: Which kind of pointer do I use when? I read that std::auto_ptr is obsolete, so you must use std::tr1::shared_ptr instead. As I read difference is std::tr1::shared_ptr have reference counting, while std::auto_ptr haven't, so…
Alecs
  • 2,256
  • 8
  • 32
  • 45
0
votes
2 answers

dynamic memory allocation for auto_ptr

This is a sample code of my program. Here I am dynamically allocating memory using std::auto_ptr and entering values( in function) after that I am again allocation memory for the same variable. So Do the previously allocated memory will be…
Aneesh Narayanan
  • 3,220
  • 11
  • 31
  • 48
0
votes
1 answer

In C++03 auto_ptr why isn't compiler generated copy-ctor called?

I understand how auto_ptr works in C++03. It is based on this trick. The trick uses a user-defined conversion to steal the pointer from one object to another when code such as this auto_int p(auto_int(new int())); is written. However, I've several…
Sumant
  • 4,286
  • 1
  • 23
  • 31
0
votes
1 answer

how to check auto_ptr is already pointing to an object or not

I currently have an auto_ptr: auto_ptr classA_; How can I check whether classA_ points to something or not. If I do: if (classA_ == NULL) to check if its pointing to NULL, it is giving a compile error: error: no match for 'operator=='…
Romonov
  • 8,145
  • 14
  • 43
  • 55
0
votes
1 answer

How to use smart pointer (e.g. auto_ptr r shared_ptr) to generate a link list data structure in C++ on Linux?

This is a C++ programming problem. I need to generate a list and return a pointer so that other functions can use the list. The code works but has memory leak because I use "new" to allocate each new node for the list. After using the list I have…
user1002288
  • 4,860
  • 10
  • 50
  • 78
0
votes
2 answers

compile error in template member conversion operator

I'm trying to write a conversion operator function template in a class and running into some compile errors which I don't fully understand. class ABC { }; class BBC:public ABC { }; template class TestPtr { public: TestPtr(T*…
hawk
  • 1,827
  • 2
  • 14
  • 28
-1
votes
2 answers

Return auto_ptr payload by value in C++ from function

Does C++ standard guarantee that here would be no crash when returning auto_ptr's payload by value from the function: class Foo { ... }; std::auto_ptr createFoo() { return std::auto_ptr(new Foo(...)); } ... Foo getFoo() { …
barankin
  • 1,853
  • 2
  • 12
  • 16
-1
votes
2 answers

Why elements in a vector need to be copy constructable?

I have this question because I am reading the section for auto_ptr. It says auto_ptr cannot be saved in a vector because of its destructive copy and assignment. I can understand it somehow and one example I can think of is something like auto_ptr ap…
Sean
  • 2,649
  • 3
  • 21
  • 27
1 2 3
13
14