There are several things
throw;
is used to
rethrow, that is, you catch the exception, handle as you can, and then propagate it upwards.
To actually throw, you need to especify what are you throwing. By instance
throw std::runtime_error("some helpful message");
Don't throw from destructors
https://isocpp.org/wiki/faq/exceptions#ctor-exceptions
https://isocpp.org/wiki/faq/exceptions#dtors-shouldnt-throw
Leaks all over the place.
your constructor is allocating dynamically
myptr(new T(*ptr))
, yet when creating the variable you are already doing that
my_auto_ptr<int> p2(new int(6));
. So 2 allocations, but only 1 delete.
Also, ¿what would happen if you
my_auto_ptr<Base> foo( new Derived() );
?
Missing copy constructor and assignment operator. Although you probably code them later, ¿right?
Till then, you may mark them as non-existant
my_auto_ptr( const my_auto_ptr &) = delete;
¿Why do you consider an error for `myptr' to be null in the destructor?
1 2 3 4 5 6
|
T& operator* () const {
if (*myptr) //dereferencing, so T must be able to convert to bool
return *myptr;
else
throw; //¿is it an error for the object pointed to be false?
}
|