| <<< Passing parameters by value | Index | The need for struct pointer, cont. >>> |
To make normalize() work with the original rect instantiated by main(), we must pass the object by pointer:
void normalize( Rectangle* ptr_rect )
{
(*ptr_rect).set_dimensions( 1, 1 );
}
Note that the pointer has to be dereferenced (*ptr_rect) before accessing the rectange in memory.
Alternatively, a member selector operator -> is typically used with pointers to structs, because it makes code more readable:
void normalize( Rectangle* ptr_rect )
{
ptr_rect->set_dimensions( 1, 1 );
}
| <<< Passing parameters by value | Index | The need for struct pointer, cont. >>> |