B
BekTek
How do you think?
and why?
and why?
BekTek said:How do you think?
and why?
Matthias Kappler said:Boost has several different smart pointer types, each tailored for a
specific need, which allows for more flexibility. I would go with boost.
I have even heard that boost smart pointers are subject to enter the C++
standard library on the next revision.
- Matthias
BekTek said:How do you think?
and why?
BekTek said:How do you think?
and why?
Cy Edmunds said:They both have their uses, so I wouldn't call one "better". However,
std::auto_ptr does have a characteristic which is hard to like: for
auto_ptr's x and y
y = x;
changes both x and y. This can certainly cause confusion in use.
Jonathan Turkanis said:This one of the main attractions of move_ptr: the above won't compile. If you
really want to transfer ownership from x to y, you have to write
y = move(x);
Jonathan said:This one of the main attractions of move_ptr: the above won't compile. If you
really want to transfer ownership from x to y, you have to write
y = move(x);
Dietmar Kuehl said:Apparently I have become seriously stupid but I don't see it:
| std::auto_ptr<int> x(new int(1));
| std::auto_ptr<int> y;
| y = x;
You seem to assert that the assignment in the above statement does not
compile. I can see that it may have unexpected behavior but not that it
does not compile. Can you please shed some light on this? Maybe you
were
refering to the situation where a function is returning an 'auto_ptr':
| std::auto_ptr<int> foo() { return std::auto_ptr<int>(new int(1)); }
| int main() {
| std::auto_ptr<int> x = foo(); // OK: there is a special ctor (*)
| x = foo(); // error: need non-const reference
| }
Howard Hinnant said:"Dietmar Kuehl" <[email protected]> wrote:
Hi Dietmar,
What Jonathan meant was that if the type of the smart pointer is
move_ptr, instead of auto_ptr, then the assignment won't compile:
y = x; // compile time error
This is a safety feature of move_ptr, especially in generic code where
moving from lvalues with copy syntax can render the generic algorithm
incorrect.
-Howard
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.