The word you’re looking for is “declare”, not “prototype”.
In any case, that’s normal. Usually you’d just include the relevant header files:
// ClassB.h
#include "ClassA.h"
class ClassB {
public: ClassA* ca; };
This will cause problems with circular references, though (but in all other cases it’s fine).
Another thing: Don’t forget your include guards, to protect against multiple inclusion of a file. That is, always write header files in the following way:
#ifndef UNIQUE_IDENTIFIER_HERE
#define UNIQUE_IDENTIFIER_HERE
// Rest of header file here.
#endif // ndef UNIQUE_IDENTIFIER_HERE
The UNIQUE_IDENTIFIER_HERE
is usually an all-uppercase variant of the header file name, e.g. ‹PROJECTNAME›_‹PATH_TO_HEADER›_‹HEADERNAME›_H
. For example, I’m currently working in a project (called “SeqAn”) that has a header file in the path parallel/taskdata.h
. The unique identifier I use is thus SEQAN_PARALLEL_TASKDATA_H
.