(, ), . Base .
, Base. Base , Derived ( ), Base.
EDIT:
, :
int main () {
boost::optional x(Derived());
func(x);
}
:
, - :
int main () {
boost::optional<Base> x = Derived();
func(x);
}
( , Visual Studio 2013 Boost 1.60) . :
#include <boost/optional.hpp>
#include <iostream>
class Base
{
public:
virtual ~Base() { std::cout << "~Base" << std::endl; }
};
class Derived : public Base
{
public:
virtual ~Derived() { std::cout << "~Derived" << std::endl; }
};
int main()
{
boost::optional<Base> x = Derived();
}
~Derived
~Base
~Base
~Base , optional Base, Derived. (~Derived Derived(), ~Base.)