Given the relationship of classes shown in the code below:
class Base
{
virtual getValue() { return 0; }
};
class Derived: public Base
{
getValue() override { return 1; }
};
class Another
{
Base* makeClass( bool );
void createVector();
};
Base* Another::makeClass( bool base )
{
if( base )
{
return new Base();
}
else
{
return new Derived();
}
}
void Another::createVector()
{
std::vector<Base> vector;
vector.emplace( *makeClass( false ) );
std::cout << vector[0].getValue();
}
Why does it print 0
instead of 1
?
Is it converting the Derived*
into a Base
when added to the vector?