0

I am working with a c++ library that is not written by me.

Some header files include other classes, but still have sort of "duplicate" empty definition of the class. What is the purpose of this behaviour?

#include "OtherClass.h"


class OtherClass;

class ThisClass {
    // definitions here
};
Jarod42
  • 203,559
  • 14
  • 181
  • 302
mario.schlipf
  • 1,257
  • 2
  • 13
  • 29

1 Answers1

2

This is a forward declaration of the class which is a declaration without a complete definition of the identifier. This helps reducing the compile time and also the circular dependencies.

In your scenario you only should include or forward declare the class, but not both.

nomann
  • 2,257
  • 2
  • 21
  • 24