FrictionalGames/HPL1Engine — comment on commit 937da49b415735c95f840edd8e7414f6fccd4a56
File:  line 0
By losinggeneration:

Really it would be better here if the AddIndextToBatch(const cVertex *apVtx); where changed to be const reference instead. This breaks the API, but the resulting API is much better and less error prone for anyone thinking about using the engine. If someone where to right now pass NULL as a parameter the engine will crash from dereferencing a NULL pointer (and this is true of all the AddIndexToBatch functions from the looks of it.) Using the const & also allows the original code to be mostly usable.

```C++
mpLowLevelGraphics->AddVertexToBatch(cVertex(vEndPos[1],ShadowColor));
```

The above would be perfectly valid using a const reference. A general rule when to pass by reference and when to pass by pointer is if ownership is taken over or the value is modified in the function, a pointer should (or really, must in the first case) be used. If you need to pass non-trivial types, but the value is not changed in the function, use a const reference. What these two rules do is allows you to know if the variable is being changed or taken over by the function without having to look back at the declaration for the function. So if you have:

```C++
func(&x);
```
You know that func is going to be taking x as a pointer and changing it (or possibly taking control over ownership of the pointer, which would be the case if it was to later free x)

The second rule then allows you to write:

```C++
func(v);
func(Vertex(5.3,10.9));
```
The first looks just like you would expect for pass by value so without even seeing the function declaration, you know the value isn't going to change. The second is also possible (which is related to this directly) because pass by reference can work with temporary values whereas pass by pointer cannot. (Think of how you pass objects when doing operator overloading.)