auto-ptr Questions

9

Solved

When using the pImpl idiom is it preferable to use a boost:shared_ptr instead of a std::auto_ptr? I'm sure I once read that the boost version is more exception friendly? class Foo { public: Foo()...
Carpology asked 22/11, 2008 at 10:3

3

Solved

Some of my colleagues prefer to explicitly initialize std::auto_ptr to 0 in constructor initialization list, but it will be initialized to 0 in it's constructor without any explicit initialization....
Heal asked 6/10, 2011 at 9:21

4

Solved

I learned that STL can forbid programmer putting an auto_ptr into a container. For example following code wouldn't compile: auto_ptr<int> a(new int(10)); vector<auto_ptr<int> >...
Lassalle asked 9/9, 2011 at 8:56

3

Solved

I came accross several questions where answers state that using T* is never the best idea. While I already make much use of RIIC, there is one particular point in my code, where I use T*. Reading ...
Monogenic asked 20/7, 2011 at 12:19

4

I'm using auto_ptr<> which uses an array of class pointer type so how do I assign a value to it. e.g. auto_ptr<class*> arr[10]; How can I assign a value to the arr array?
Phenocryst asked 29/6, 2011 at 12:46

4

Solved

Lets say I have heap allocated A*, which I want to pass as argument to boost::bind. boost::bind is saved for later processing in some STL like container of boost::functions's. I want to ensure A* ...
Frenchman asked 11/5, 2011 at 12:3

1

Solved

When trying to use an auto_ptr with a type that was declared with forward-declaration, like this: class A; ... std::auto_ptr<A> a; the destructor of A is not called (apparently, because au...
Steed asked 9/4, 2011 at 17:50

6

Solved

Occasionally, for fleeting moments, I think auto_ptr is cool. But most of the time I recognize that there are much simpler techniques that make it irrelevant. For example, if I want to have an obje...
Bluegill asked 26/1, 2011 at 7:45

5

Solved

I need to obtain auto_ptr from shared_ptr in my code. I can do reverse operation - convert auto_ptr to shared_ptr as shared_ptr has such constructor: template<class Y> explicit shared_ptr(st...
Phoebe asked 23/1, 2011 at 11:27

4

Solved

After reading Jossutis' explanation on auto_ptr from his STL book I've got a strong impression that whatever task I would try to use it in I'd 100% fail becuase of one of many auto_ptr's pitfalls. ...
Semmes asked 29/12, 2010 at 12:40

1

Solved

std::auto_ptr is not allowed to be stored in an STL container, such as std::vector. However, occasionally there are cases where I need to return a collection of polymorphic objects, and therefore I...
Horrific asked 25/12, 2010 at 20:51

3

Solved

Back on my crazy AutoArray thingy... (quoting important bits from there: class AutoArray { void * buffer; public: //Creates a new empty AutoArray AutoArray(); //std::auto_ptr copy semantics A...
Yousuf asked 22/12, 2010 at 22:0

4

Solved

Consider the following example code which I have recently seen in our code base: void ClassA::ExportAnimation(auto_ptr<CAnimation> animation) { ... does something } // calling method: void ...
Pecan asked 9/8, 2010 at 11:56

4

Solved

The Title pretty much sums up my question. Why can't the following be done to check for a null pointer? auto_ptr<char> p( some_expression ); // ... if ( !p ) // error This must be done ins...
Maag asked 30/6, 2010 at 16:51

2

Solved

Consider the following code: #include <iostream> #include <memory> #include <vector> using namespace std; struct A { int a; A(int a_):a(a_) {} }; int main() { vector<aut...
Estrella asked 15/4, 2010 at 8:20

1

is the following function OK: void DoSomething(auto_ptr< … >& a)....
Klansman asked 21/3, 2010 at 9:57

3

Solved

We've pretty much moved over to using boost::shared_ptr in all of our code, however we still have some isolated cases where we use std::auto_ptr, including singleton classes: template < typenam...
Recount asked 4/8, 2009 at 12:58

2

Solved

Why this code does not cause memory leaks? int iterCount = 1000; int sizeBig = 100000; for (int i = 0; i < iterCount; i++) { std::auto_ptr<char> buffer(new char[sizeBig]); } WinXP sp2,...
Trodden asked 29/7, 2009 at 7:32

7

Solved

Could somebody please explain to me why does this code only print "42" instead of "created\n42"? #include <iostream> #include <string> #include <memory> using namespace std; cl...
Numidia asked 18/7, 2009 at 19:11

9

Solved

I have class foo that contains a std::auto_ptr member that I would like to copy construct but this does not appear to be allowed. There's a similar thing for the assignment. See the following examp...
Waterage asked 17/7, 2009 at 11:11

5

Solved

I want to return two values, one of which is a new object. I can do this using std::pair: class A { //... }; std::pair<A*, int> getA() { A* a = new A; //... } To make the code exceptio...
Tuneful asked 22/6, 2009 at 17:41

4

Solved

I ran into a compiler error that didn't make much sense to me: #include <memory> using namespace std; auto_ptr<Table> table = db->query("select * from t"); error: conversion from...
Upper asked 16/4, 2009 at 18:32

© 2022 - 2024 — McMap. All rights reserved.