View Single Post
Old 19th May 2004, 20:54     #16
Adaptation
 
Quote:
Originally posted by Polarity
While I agree with your sentiment, objects are not the same thing as procedures and neither are switch statements the same thing as object hierarchies with virtual functions. Maybe you could explain the other "half" that some people appear to be missing.
Here we go into the lands of offtopic with 'Switch statements and object hierarchies with virtual functions 101'

Code:
int eat_apple() { // eat an apple return 1; } // eat a food type, return 0 if we don't know the food type int eat_food(int food_type) { switch (food_type) { case APPLE: return eat_apple(); // etc etc default: return 0; } } // somewhere in code int food_type = APPLE; int eaten = eat_food(food_type);
Code:
struct Food { // eat a food type, return false if we don't know the food type virtual bool Eat(void) { return false; } }; struct Apple : public Food { bool Eat(void) { // eat an apple return true; } }; // etc etc // somewhere in code Apple apple; Food* food = &apple; bool eaten = food->Eat();
As for objects not being the same thing as procedures go do a search for functor's.

Last edited by Adaptation : 19th May 2004 at 20:57.
  Reply With Quote