next up previous
Next: What is a pure Up: class and struct Previous: How do I avoid


What is a virtual method?

A virtual method in a parent allows children to have a different implementation for it. A pure virtual method in a parent forces children to have an implementation for it (interface in Java). A class with a pure virtual method is called virtual.

struct A
{
  virtual void	f1() = 0;
  virtual void	f2() { /* ... */ }
};

struct B: public A
{
  void	f1() { /* ... */ }
};

struct C: public A
{
  void	f1() { /* ... */ }
  void	f2() { /* ... */ }
};



Alexis Angelidis (PhD) 2005-01-11