![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
|
Hello all
![]() I have been asking myself what are the essential differences between references and pointers. The only thing I could think of was that dynamic alocation is done with pointers. So, generally, when should I use pointers and references ? Can I replace every reference with the pointer equivalents and vice-versa ? Thanks in advance Cheers, gamehack |
|
|
|
|
|
#2 |
|
Programmer
Join Date: Sep 2004
Location: JHB , South Africa
Posts: 79
Rep Power: 5
![]() |
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.
__________________
Ravilj's OpenGL Terrain aka WinTerrain Last Updated: 17/01/2005! |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|