The C++Course provides a general introduction to programming in C++. It is based on A.B. Downey's book, How to Think Like a Computer Scientist. Click here for details.

Defining an Abstract Class

An abstract class definition looks a lot like a concrete class definition, except that it only specifies the interface of each method and not an implementation. The definition of Visitable is

public interface Visitable {
    public void visit ();

That's it! The word interface is C++'s keyword for an abstract class. The definition of visit looks like any other method definition, except that it has no body. This definition specifies that any class that implements Visitable has to have a method named visit that takes no parameters and that returns void.

Like other class definitions, abstract class definitions go in a file with the same name as the class (in this case Visitable.cpp).

Last Update: 2005-12-05