c++ - The differences between initialize, define, declare a variable -
after reading question, know differences between declaration , definition. mean definition equals declaration plus initialization?
declaration
declaration, generally, refers introduction of new name in program. example, can declare new function describing it's "signature":
void xyz();
or declare incomplete type:
class klass; struct ztruct;
and last not least, declare object:
int x;
it described, in c++ standard, @ §3.1/1 as:
a declaration (clause 7) may introduce 1 or more names translation unit or redeclare names introduced previous declarations.
definition
a definition definition of declared name (or can both definition , declaration). example:
int x; void xyz() {...} class klass {...}; struct ztruct {...}; enum { x, y, z };
specifically c++ standard defines it, @ §3.1/1, as:
a declaration definition unless declares function without specifying function’s body (8.4), contains extern specifier (7.1.1) or linkage-specification25 (7.5) , neither initializer nor function- body, declares static data member in class definition (9.2, 9.4), class name declaration (9.1), opaque-enum-declaration (7.2), template-parameter (14.1), parameter-declaration (8.3.5) in function declarator not declarator of function-definition, or typedef declaration (7.1.3), alias-declaration (7.1.3), using-declaration (7.3.3), static_assert-declaration (clause 7), attribute- declaration (clause 7), empty-declaration (clause 7), or using-directive (7.3.4).
initialization
initialization refers "assignment" of value, @ construction time. generic object of type t
, it's in form:
t x = i;
but in c++ can be:
t x(i);
or even:
t x {i};
with c++11.
conclusion
so mean definition equals declaration plus initialization?
it depends. on talking about. if talking object, example:
int x;
this definition without initialization. following, instead, definition initialization:
int x = 0;
in context, doesn't make sense talk "initialization", "definition" , "declaration". if talking function, example, initialization not mean much.
so, answer no: definition not automatically mean declaration plus initialization.
Comments
Post a Comment