Empty class declaration in header file?

c++, class, header-files

Solution

It's a forward declaration.

It's just there to inform the compiler that a class template named `Robot` will be defined later and that it should expect that definition.

In the meantime (i.e., until `Robot` is officially defined), it allows the programmer to refer to that type in the code. In the example you've given, it is necessary to declare `Robot` as a `friend` of the `Happy` class. (Who picked these names?!)

It's a common strategy to avoid circular dependencies and minimize compilation time/overhead.

Problem

Possible Duplicate: What is forward declaration in c++? I just have a question about what a piece of code is doing in this simple example. I've looked up friend classes and understand how they work, but I don't understand what the class declaration at the top is actually doing (i.e. Robot). Does this just mean that the Happy class can use Robot objects but they can't access its private parts, any information would be appreciated. ``` #include <stdlib.h> #include <stdexcept> template <typename T> // What is this called when included class Robot; // is there a special name for defining a class in this way template <typename T> class Happy { friend class Joe<T>; friend class Robot<Happy<T> >; // ... }; ```

Original source

Related problems