Skip to main content
gamedev.net
🔒 Locked

references vs pointer

Started by silentmonk 0 replies 250+ views
Original Post
silentmonk
silentmonk
i have read examples of references and have seen that by using references the object which is taken by the function as argument doesnt call the constructor function which is good in terms of memory allocate/deallocate but whats the real differences between pointer/references...since references is an explicit poointer or something what is the exact definition of references anyway with regards SilentMonk
"If you can''t explain something simply, you don''t know enough about it."- Albert Einstein
Painless
Painless
You seem quite confused. Well, I think these are the main differences:

References
- must initially point to an existing object (but there''s nothing preventing you from taking a reference to an object, then deleting the object through a pointer, or returning a reference to a stack object)
- can''t be 0 (or NULL, however you like it)
- can''t use pointer arithmetic
- can''t be reassigned

Anyways, I think references are usually implemented as pointers, but it shouldn''t make any difference anywhere how they work.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.