
Ralf W. Grosse-Kunstleve wrote:
In contrast to the STLport implementation I use this approach to implement the copy constructor (and similarly for the assignment operator):
class auto_array { mutable T* ptr;
auto_array(auto_array const& other) { ptr = const_cast<auto_array*>(&other)->release(); } };
I know it works on a large number of platforms (several versions of EDG, VC, g++). valgrind also didn't have any complaints. Is the approach also OK from a theoretical viewpoint?
I don't know about STLport's approach, but const-casting the parameter is definitely not OK from a theoretical viewpoint. Your const parameter is a promise that you won't modify the parameter, but then you go ahead and do it anyway. You should make the parameter non-const, like the GNU C++ library does with auto_ptr: auto_ptr(auto_ptr& __a) throw() : _M_ptr(__a.release()) { } Sebastian Redl