T
Tom Wilson
Is there a way to pass a derived object so that the called function thinks
it is the base class?
Here's the lowdown.
class Hull
{
// ....
virtual int DoIt() { TRACE("Hull"); }
// ....
}
class ConvexHull : public Hull
{
// ....
int DoIt() { TRACE("ConvexHull"); }
// ....
}
class Fitted
{
// ....
int FitHull(Hull *in_phull) { in_phull->DoIt(); }
// ....
}
main()
{
Fitted fittedData;
ConvexHull chull;
Hull *phull=&chull;
fittedData.FitHull(&chull);
fittedData.FitHull(phull);
}
Output is:
ConvexHull
ConvexHull
Is there a way to pass phull so that it forgets about its derived class? I
want the output to be:
ConvexHull
Hull
Thanks.
it is the base class?
Here's the lowdown.
class Hull
{
// ....
virtual int DoIt() { TRACE("Hull"); }
// ....
}
class ConvexHull : public Hull
{
// ....
int DoIt() { TRACE("ConvexHull"); }
// ....
}
class Fitted
{
// ....
int FitHull(Hull *in_phull) { in_phull->DoIt(); }
// ....
}
main()
{
Fitted fittedData;
ConvexHull chull;
Hull *phull=&chull;
fittedData.FitHull(&chull);
fittedData.FitHull(phull);
}
Output is:
ConvexHull
ConvexHull
Is there a way to pass phull so that it forgets about its derived class? I
want the output to be:
ConvexHull
Hull
Thanks.