@Chervil
One could argue that defining a POD variable and initialisation are the same thing. I did not mean that defining is allocating storage - that is what declaration does.
1 2
|
int a; // allocate storage (declaration)
int b = 10; // allocate storage and initialise
|
@YellowPyrmid
MSDN wrote: |
---|
A declaration introduces one or more names into a program. Declarations can occur more than once in a program. Therefore, classes, structures, enumerated types, and other user-defined types can be declared for each compilation unit. The constraint on this multiple declaration is that all declarations must be identical. Declarations also serve as definitions, except when the declaration:
1 Is a function prototype (a function declaration with no function body).
2 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.
3 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 Classes.)
4 Is a class name declaration with no following definition, such as class T;.
5 Is a typedef statement.
|
So I think you misread that a bit.
Declarations tell the compiler that a program element or name exists. Definitions specify what code or data the name describes. A name must be declared before it can be used. |
Ok, that's fine. But I don't see how
int i;
can be a definition.
Examples of declarations that are also definitions are: |
My interpretation:
i is declared but not defined (not initialised with anything)
j is declared and defined (initialised with value 10)
enum suits is declared and defined
1 2 3 4 5 6 7
|
// Declare class CheckBox.
class CheckBox : public Control
{
public:
Boolean IsChecked();
virtual int ChangeState() = 0;
};
|
I wouldn't call that code a definition, in my mind a class declaration is what one puts in a header file, it's definition (that is it's function definitions) are in the implementation file .cpp.
Also I wouldn't consider
CheckBox
as defined because it is incomplete, never mind the pure virtual function, there is no definition for the IsChecked() function. If that function definition was inline then it would be.
A forward declaration of this class would just be
class CheckBox;