// Try looking at the assembly for this code:
//    objdump -d vtable > vtable.s
// You can also use gdb to look at the vtables:
//    (in gdb:)
//    info vtbl h
//    info vtbl pdog
//    info vtbl dog
// Or look at the memory directly, if you're feeling adventurous

#include <iostream>

using namespace std;

class Dog {
public:
  virtual void bark() { cout << "Dog!" << endl; }
  virtual void sit() { cout << "Woof!" << endl; }
  void stay() { cout << "Arf arf!" << endl; }
private:
  int _x;
  int _y;
};

class Husky : public Dog {
public:
  void bark() { cout << "Husky" << endl; }
  void sit() { cout << "Woof! Beat the Cougars!" << endl; }
  void stay() { cout << "Arf arf! Beat the Ducks!" << endl; }
};

int main(int argc, char** argv) {
  Husky h;
  h.bark();
  h.sit();
  h.stay();

  Dog *pdog = &h;
  pdog->bark();
  pdog->sit();
  pdog->stay();

  Dog dog;
  dog.bark();
  dog.sit();
  dog.stay();

  Dog& rdog = h;
  rdog.bark();
  rdog.sit();
  rdog.stay();

  return 0;
}