View Single Post
Old Oct 2nd, 2004, 11:37 AM   #12
Ravilj
Programmer
 
Ravilj's Avatar
 
Join Date: Sep 2004
Location: JHB , South Africa
Posts: 79
Rep Power: 5 Ravilj is on a distinguished road
Quote:
Originally posted by Myself (to lazy to retype it)

References are used mainly for passing large structures to functions. When passing data to functions you have 2 options:
1. Pass by value
This passes a new instance of the variable to the function.
2. Pass by reference
This passes the address of the varaible to the function.

Passing by reference is more efficient as well as it still allows you to use the variables name with out having to worry about dereferencing it. References also allow you to change the data of the variable passed without having to return it. This can be a good thing and a bad thing so 'const' is often used in conjunction with references.

References are choosen above pointers for this reason since they are easier to use. Pointers are gernerally left for dynamically allocating memory and such and referencing dynamic objects.
References vs. Pointers
__________________
Ravilj's OpenGL Terrain aka WinTerrain Last Updated: 17/01/2005!
Ravilj is offline   Reply With Quote