Whilst the following code works perfectly well, I'm wondering if this is the best way to do it, and also, although Cfish is the base class of both Csalmon and Cpike, shouldn't it require a cast to assign one of those to the Cfish ?
Code:class Cfish { public: virtual int feed (void) = 0; }; class Cpike : public Cfish { public: int feed (void); }; class Csalmon : public Cfish { public: int feed (void); }; int Cpike::feed(void) { printf ("Pike feeding.\n"); return 1; } int Csalmon::feed(void) { printf ("Salmon feeding.\n"); return 1; } int _tmain(int argc, _TCHAR* argv[]) { Cfish *fish; fish = new Csalmon; // why no cast needed here? fish->feed(); delete fish; fish = new Cpike; // or here? fish->feed(); delete fish; return 0; }