A declaration introduces one or more names into a program. Declarations also serve as definitions, except in the following cases:
The declaration is a function prototype (a function declaration with no function body).
The declaration contains the extern specifier but no initializer (objects and variables) or function body (functions). This signifies that the definition is not necessarily in the current translation unit and gives the name external linkage.
The declaration is of a static data member inside a class declaration.
Because static class data members are discrete variables shared by all objects of the class, they must be defined and initialized outside the class declaration. (For more information about classes and class members, see Chapter 8, “Classes.”)
The declaration is a class name declaration with no following definition.
The declaration is a typedef statement.
Examples of declarations that are also definitions are:
// Declare and define int variables i and j.
int i;
int j = 10;
// Declare enumeration suits.
enum suits { Spades = 1, Clubs, Hearts, Diamonds };
// Declare class CheckBox.
class CheckBox : public Control
{
public:
Boolean IsChecked();
virtual int ChangeState() = 0;
};
Some declarations that are not definitions are:
extern int i;
char *strchr( const char *Str, const char Target );