class Base {
public:
virtual Base* DoComputation() {
// do computations
// return a pointer to a new instance of **Base**
}
};
class Derived : public Base {
public:
virtual Base* DoComputation() {
// do computations
// return a pointer to a new instance of **Derived**, which will be
// upcasted to Base
}
void DummyFunction() {}
};
Base* pDerived = new Derived;
Base* pResultOfComputation = pDerived->DoComputation();
static_cast< Derived* >(pResultOfComputation)->DummyFunction();
class Base {
public:
virtual Base* DoComputation() {
// do computations
// return a pointer to a new instance of **Base**
}
};
class Derived : public Base {
public:
virtual Derived* DoComputation() {
// do computations
// return a pointer to a new instance of **Derived**, which will be
// upcasted to Base
}
void DummyFunction() {}
};
Base* pDerived = new Derived;
Derived* pResultOfComputation = pDerived->DoComputation();
pResultOfComputation->DummyFunction();