Quote Originally Posted by whiteflags View Post
You're probably asking about polymorphism. In C++ virtual functions make it work:

Code:
#include <iostream>
using namespace std;
class Foo {
   private:
   int data;

   public:
   Foo(int d = 0) : data(d) { }
   virtual ~Foo() { }
   virtual void displayData() const { cout << "data=" << data << endl; }
};
class Bar : public Foo {
   private:
   int moreData;

   public:
   Bar(int d = 0, int dd = 0): Foo(d), moreData(dd) { }
   virtual ~Bar() { }
   virtual void displayData() const { 
      Foo::displayData();
      cout << "moreData=" << moreData << endl; 
   }
};
void func(Foo& thing) {
   // Be polymorphic:
   thing.displayData();
}
int main() {
   Bar b1(42, 24);
   Foo f1(256);
   func(b1);
   cout << endl;
   func(f1);
   return 0;
}
C++ code - 35 lines - codepad

Kind of a stupid example really, but you can see the change in behavior in spite of my questionable use of func().
No, I like it. I was just curious if Poo or Boo could be accessed via Foo but it appears any such access must be polymorphic and your example is quite clear there.