smart pointer questions

Started by
0 comments, last by SiCrane 18 years, 5 months ago
I have a question about smart pointers: What if you are passing a dereferenced object in an array? How do you tell the user not to use a smart pointer with that? And if you mix normal pointers with smart pointers, wouldn't it be confusing?
Advertisement
Passing a dereferenced object shouldn't work, as there would be a type incompatibility. If you mean passing a pointer to an object in an array, then the smart pointer will probably try to delete it, and either crash the program or corrupt the heap. Don't do that.

This is one reason why smart pointers usually accept pointers as constructor arguments for explicit constructors and do not accept pointers as arguments to the assignment operator. When you can only initialize a smart pointer with a pointer at construction, it limits the amount of accidental damage you can do.

This topic is closed to new replies.

Advertisement