Your code looks OK to me but has a few problems:
1) You need to protect against self assignment. Think about what will happen if someone does this:
1 2 3
|
smartPTR<int> foo = new int(10);
foo = foo; // self assignment -- will make your class explode
|
2) You are not const correct
3) Since your smart pointer class is only for
single element pointers (since you're using delete and not delete[]), you should not have the [] operator.
4) You also should not have -- or ++ operators, because changing the pointer will make it impossible to delete properly. And again is pointless for a single element pointer class.
5) As coder777 said, smart pointer classes are meant to manage memory allocated with new. If you are not allocating the object with new, there's no reason to use a pointer class (and the pointer class will crash.
6) up/downcasting for polymorphism would be a plus