Introduction to Programming and C++

Contents Previous Topic Next Topic

Like a variable declaration, the simplest class declaration simply indicates that a symbol is a class:

class ClassName;

This indicates to the compiler that ClassName should be interpreted as a class. After such a declaration, it is possible to use ClassName as a type in a function declaration even if the class has not been defined (or perhaps is defined in a different file/library).

For example, the following is valid:

class ClassName;

void f( ClassName arg );

Templates

To declare a class associated with a templated typename, simply include the template modifier:

template <typename T>
class ClassName;

Any statement using this class must also have the template modifier, however, if the function is not itself using the template, you must specify that the function is not templated using ><, for example:

template <typename T>
class ClassName;

template <typename T>
void f<>( ClassName<T> arg );

Contents Previous Topic Top Next Topic