I'm going through an exercise to clean up my code and put some more logic in it, regarding passing references and pointers.
Here's my goal:
** applies to all global functions and member functions of my classes
** if a function parameter is a class which is only input (not to be changed), use a const reference (const &...)
** if a function parameter needs to be altered by the function, use a pointer to the object (*....)
This also gives good readability if a function is changing an object, noticed by "->...".
** when it regards passing 'simple' objects like a vector/vertex, matrix, int, float etc., that is only input (not to be changed), I use const only (no reference). For example:
float DistCoordToCoord(const D3DXVERTEX3 pVector1, const D3DXVECTOR3 pVector2); or
** when it regards passing 'simple' objects which need to be altered, I use a pointer. For example:
void DistCoordToCoord(const D3DXVERTEX3 pVector1, const D3DXVECTOR3 pVector2, float *pResult);
The aim is to get better readability and less fault risks, by applying these style/ correctness.
- what would you do, looking at this? other approaches/ better approaches?
- am I overseeing things?
First thing I'm gonna do now is create a nice XLS with all classes and functions where this applies.
So any input is appreciated and can be used, since I'll need some time first to get the overview