7.0 Classes
The only exception is using methods like these which are used only to return a return type of a more derived type.
class X {
public:
void bar () { writeFile(); }
X* ok () { return findParent();}
};
class Y : public X {
public:
void bar () { ringBell(); }
Y* ok () { return (Y*) X::ok(); }
};
void foo ()
{
Y* yp= new Y; // one instance of Y
X* xp = yp; // point to same instance as an X
Y* foundY = yp->ok (); // ok
X* foundX = xp->ok (); // ok
xp->bar (); // ok, file written
xp->bar (); // surprise! your bell was rung!
}
Generated with CERN WebMaker