I am using C ++. C ++ 0x using Visual Studio 2010 to be true.
Suppose I have a class Z. To make it safer to work with pointers to this class in my application, I can use smart pointers (general pointer, weak pointer) in sequence.
Now this class Z inherits from class X. Some parts of my application will work with pointers to class X, others will work with pointers to class Z.
- Can I use smart pointers?
- Are shared pointers shared if I have references to X and others related to Z? Is it guaranteed that destroying the last common instance pointer (whether it is
std::shared_ptr<X>or std::shared_ptr<Z>) removes the instance? I am sure that if I delete std::shared_ptr<X>that the instance is saved as long as there is another one std::shared_ptr<Y>?
Now suppose I use multiple inheritance, where Z inherits from classes X and Y. Some parts of my application will work with std::shared_ptr<X>, others with std::shared_ptr<Y>and others with std::shared_ptr<Z>.
- Can I use generic pointers this way?
- Is it guaranteed that only the last smart pointer (regardless of whether it points to X, Y or Z) deletes the instance?
, , . std::shared_ptr<Z> std::shared_ptr<X>? ? ?
, ( std::shared_ptr std::weak_ptr ++ 0x). (, Boost) , , , .