E.g.
extern int x; //object declaration
class ABC; // Class declaration
template<typename T> struct XYZ; //template declaration
Declarations introduce new names into a program. Topics covered in this section include the following uses for declarations.
- Associate a name with a constant (enumeration declaration).
- Specify a synonym for a type (typedef declaration).
- Specify a namespace.
A definition provides compilers with the details the declaration omits. It is different for different types as follows:
1) For an object, the definition is where the compiler set aside the memory for the object.
2) For a function or function template, the definition provides the code body.
3) For a class or class template, the definition lists the member of the class or templates.
e.g.
int x; // object definition
class ABC { // class definition
private:
int i;
}
template <typename T> struct XYZ { // template definition
int i;
}
Initialization is the method of giving an object its first value. For objects generated from structs and classes, initialization is performed by constructors. Copy constructor is used to initialize an object with a different object of the same type.
References:
1) http://msdn.microsoft.com/en-us/library/sc8yf29y.aspx
2) Scott Meyers Effective C++ Chapter 0
No comments:
Post a Comment