Created on 2000-06-30.00:00:00 last changed 172 months ago
Rationale:
The return value has uses other than cascaded assignments: a user can call an auto_ptr member function, pass the auto_ptr to a function, etc. Removing the return value could break working user code.
Proposed resolution:
Change auto_ptr::operator=() to return void instead of an auto_ptr reference.
According to section 20.4.5, the function auto_ptr::operator=() returns a reference to an auto_ptr. The reason that operator=() usually returns a reference is to facilitate code like
int x,y,z; x = y = z = 1;
However, given analogous code for auto_ptrs,
auto_ptr<int> x, y, z; z.reset(new int(1)); x = y = z;
the result would be that z and y would both be set to NULL, instead of all the auto_ptrs being set to the same value. This makes such cascading assignments useless and counterintuitive for auto_ptrs.
History | |||
---|---|---|---|
Date | User | Action | Args |
2010-10-21 18:28:33 | admin | set | messages: + msg2002 |
2010-10-21 18:28:33 | admin | set | messages: + msg2001 |
2000-06-30 00:00:00 | admin | create |