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

Is it safe to return vector>?

Possible Duplicate: Why is it wrong to use std::auto_ptr<> with standard containers? I have a function to return some Object in pointer, so I use: vector > func() { ... } I want to know whether it is safe or not?
1
vote
1 answer

Change this to use auto_ptr?

I have been reading up on the c++ auto_ptr and unique_ptr and stuff and thought to try and use them in a class I am playing with... but I was having trouble getting it to work... How would I convert these pointers to auto pointers or some equivalent…
aJynks
  • 677
  • 2
  • 14
  • 27
1
vote
4 answers

Performance of auto_ptr vs. shared_ptr

I didn't find information about performance issues with auto_ptr and shared_ptr(I use tr1 implementation). As shared_ptr is more complicated compared to auto_ptr so auto_ptr is faster? So in general question sounds like what can you say about…
Alecs
  • 2,256
  • 8
  • 32
  • 45
1
vote
3 answers

Smart Pointer (auto_ptr) behavior

Not sure if someone has already asked this, but I see a strange behavior here: I've declared two classes, one base and one derived with just one virtual method display(). class A { public: virtual void display() { cout << "base class" <<…
Shree
  • 4,627
  • 6
  • 37
  • 49
1
vote
4 answers

Initializing std::auto_ptr: "error: no match for call to ‘(std::auto_ptr) (int*)’"

I'm having trouble using std::auto_ptr. I try to compile the following on Ubuntu 11.10 using GCC 4.6.1, and I get the error message error: no match for call to ‘(std::auto_ptr) (int*)’. #include #include class Toy …
user220878
0
votes
5 answers

Semantic meanings of std::auto_ptr and boost::shared_ptr

In our large project we have a lot class with the following typedef's: class Foo { public: typedef std::auto_ptr Ptr; typedef boost::shared_ptr Ref; ... }; ... Foo::Ref foo(new Foo); ... doBar(foo); ... The using of them is…
barankin
  • 1,853
  • 2
  • 12
  • 16
0
votes
2 answers

storing pointers to auto_ptr in vector

Can one store pointers to auto_ptr(s) in a std::vector? Is it safe? I enumerate a folder reading in XML files and creating an object for each with auto_ptr. I don't know in advance how many XML files there will be and I'd like to use a vector to…
0
votes
1 answer

Why the Shape pointed by pb is destroyed when an exception is thrown in the example below?

This example was taken from Stroustup's book, third edition, Section 14.4.2 : void f (Point p1, Point p2, auto_ptr pc, Shape* pb) { auto_ptr p (new Rectangle(p1 ,p2)); auto_ptr pbox(pb); p->rotate(45); / / ... …
WaldB
  • 1,261
  • 7
  • 14
0
votes
4 answers

How to allow non-const copy constructor for temporaries

How do I allow a class with a copy constructor that takes a non-const reference to be copy-constructed from temporaries? The background is this: I have a function that should return a list of pointers to objects that all inherit from Base, so I need…
pezcode
  • 5,490
  • 2
  • 24
  • 37
0
votes
2 answers

Problems with boost::ptr_vector and boost::any

ok, so I got a doubt, I want to know if this is possible: I'm using a database, with generic data (strings, ints, bools, etc...). Whenever an object is constructed or a member of an object is modified, I have to query the database with the specific…
Ricardo Ferreira
0
votes
1 answer

In smart_ptr constructor, why pass by value and not pass by const ref?

I've been reading the section on smart pointers in Scott Meyer's "Effective C++" and "More Effective C++." In it, there is an implementation of auto_ptr for which the constructor is written as follows: template class auto_ptr{ private: …
0
votes
1 answer

How do I re-enable C++17 removed features in clang?

I have some 3rdparty libraries that are built as part of a large project. Some libraries require C++17, others require features that are removed in C++17 (std::auto_ptr, std::fun_ptr). For this project, Clang is used (version 11). From searching…
regomodo
  • 644
  • 3
  • 9
  • 18
0
votes
0 answers

storing std::auto_ptr in a container

It is said that we should always use std::unique_ptr instead of std::auto_ptr and it is said that we were not able to store a auto_ptr in a container But consider this example: int main(int argc, char* argv[]){ std::vector< std::auto_ptr >…
Itachi Uchiwa
  • 3,044
  • 12
  • 26
0
votes
0 answers

smart pointer with unexpected behavior

As i was going through smart pointers, I ran through the following code. Works as expected. #include #include using namespace std; class Double { public: Double(double d = 0) : dValue(d) { cout << "constructor: " << dValue…
Newbie
  • 204
  • 1
  • 3
  • 13
0
votes
2 answers

'no matching function for call to' error with g++ : constructor or operator = not matching?

I have a assignment operator. AP& operator=(AP& o) {Super::operator=(o); return *this; } When I expect the g++ compiler finds this operator for this code. AP to = System::Create(); I got compilation error. no matching function for…
prosseek
  • 182,215
  • 215
  • 566
  • 871