C++ Definitions

A definition is a unique specification of an object or variable, function, class, or enumerator. Because definitions must be unique, a program can contain only one definition for a given program element.

There can be a many-to-one correspondence between declarations and definitions. There are two cases in which a program element can be declared and not defined:

  • A function is declared but never referenced with a function call or with an expression that takes the function's address.

  • A class is used only in a way that does not require its definition be known. However, the class must be declared. The following code illustrates such a case:

    // definitions.cpp
    class WindowCounter;   // Forward reference; no definition
    
    class Window
    {
       // Definition of WindowCounter not required
       static WindowCounter windowCounter;
    };
    
    int main()
    {
    }
    

See Also

Reference

C++ Declarations and Definitions