Saturday, January 18, 2014

definition vs declaration c++

Declarations versus Definitions : templates tutorial ccplusplus.com
So far, the words declaration and definition have been used only a few times in this book. However, these words carry with them a rather precise meaning in standard C++, and that is the meaning that we use.
A declaration is a C++ construct that introduces or reintroduces a name into a C++ scope. This introduction always includes a partial classification of that name, but the details are not required to make a valid declaration. For example:


Note that even though they have a "name," macro definitions and goto labels are not considered declarations in C++.

Declarations become definitions when the details of their structure are made known or, in the case of variables, when storage space must be allocated. For class type and function definitions, this means a brace-enclosed body must be provided. For variables, initializations and a missing extern lead to definitions. Here are examples that complement the preceding nondefinition declarations:


By extension, the declaration of a class template or function template is called a definition if it has a body. Hence,


is a declaration that is not a definition, whereas



is in fact a definition.








-----------------------------------------------------------------
See Also:
-----------------------------------------------------------------

-----------------------------------------------------------------

No comments:

Post a Comment