Can boost::smart_ptr such as scoped_ptr and shared_ptr be used in polymorphism?
class SomeClass
{
public:
SomeClass()
{
a_ptr.reset(new SubClass);
}
private:
boost::scoped_ptr<SuperClass> a_ptr;
}
Can boost::smart_ptr such as scoped_ptr and shared_ptr be used in polymorphism?
class SomeClass
{
public:
SomeClass()
{
a_ptr.reset(new SubClass);
}
private:
boost::scoped_ptr<SuperClass> a_ptr;
}
Yes:
Output is:
Bar
I believe the answer is yes; boost pointers are coded such that derived classes are accepted wherever a superclass would be.