July 2000
Intermediate to advanced
1280 pages
34h 55m
English
When the compiler processes a definition of a variable, it uses its type definition to allocate the required amount of memory, either from the heap (for static and extern variables or for dynamic variables) or from the stack (for local automatic variables).
This is true for simple variables, arrays, structures, and classes with member functions. If the code later assigns a value to a variable, the variable does not need initialization at its definition. If the algorithm uses the variable as an rvalue, it needs initial values for its data members.
Cylinder c1; // data members are not initialized double vol = c1.getVolume(); // no, this is no good
This coding pattern, however, might be appropriate if some default ...
Read now
Unlock full access