logo

C++ - Declarations vs Definitions

  • Declaration: give it a name
  • Definition: give it a name and all the info the compiler needs to create the code for that name

In C++ there is an important distinction between a declaration (“There is a class called Foo”) and a definition (“here is class Foo including its members, methods, etc”). Since C++ attempts to be a language that can be compiled in a single pass, referring to an entity by name is an error if that entity hasn’t at least been declared at the point of that use. (Technically, a definition also counts as a declaration.)

// A forward declaration
class Foo;