Does style affect thinking?
1 2 3
|
Cube *CreateUnitCube();
Cube * CreateUnitCube();
Cube* CreateUnitCube();
|
Three examples that differ only by whitespace. All three lines are effectively identical.
There is usually debate whether first or last is "most descriptive".
The line is a declaration. There are parentheses
()
, so this declares a function.
Function declaration has at least:
returntype name () ;
In this case the
returntype, the type of the value that the function returns, is
Cube *
. Pointer to Cube. An address of some object.
The
name is
CreateUnitCube
.
The
Cube *c;
is a declaration of a variable. Type of variable is
pointer to Cube.
There is
initializer too, so the initial value of
c
is known.
1 2
|
Cube *c = CreateUnitCube() ;
Cube *c { CreateUnitCube() };
|
Again, both lines do the same. The latter syntax (with {}) has been available since C++11.
When the variable
c
is created, function
CreateUnitCube is called and whatever value is returned by the function call will be stored in
c
.