Skip to main content
GameDev.net gamedev.net
🔒 Locked

[Fixed] C++ Reference identifiers

Started by Skeleton_V@T Oct 31, 2005 at 11:01 AM 3 replies 1k views
Original Post
Skeleton_V@T
Skeleton_V@T
Hi all!. I just wonder, if reference identifiers in C++ is treated like a pointer ?. I mean when we declare/pass a reference, the compiler provides all the '*' and '->' for me ?. Is there any difference ?. Just a question to determine should I use references or come back with good old C pointers. Thanks in advance. V@T
--> The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones <--
swiftcoder
swiftcoder
References are a pointer internally, the language takes care of dereferencing etc. for you. In general references are safer than pointers (you can't easilly produce a null reference, or point it to an arbitrary location in memory).
Then again, you can't do some of the really neat (and totaly dangerous) things with references that you can do with pointers ;)
Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]
stylin
stylin
Use references whenever you can, and pointers when you have to. References are implemented differently depending on the compiler, but you can think of them as const pointers that are automatically dereferenced. They are an alias for a variable, and cannot ever point to another variable, like const pointers.
:stylin: "Make games, not war." "...if you're doing this to learn then just study a modern C++ compiler's implementation." -snk_kid
Skeleton_V@T
Skeleton_V@T
Thank you guys!. That was clarified. No wonder about it again.
++Rate ;

Should I delete such a short thread ? :/
--> The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones <--
swiftcoder
swiftcoder
Quote:
Original post by Skeleton_V@T
Thank you guys!. That was clarified. No wonder about it again.
++Rate ;

Your welcome ;)
Quote:
Should I delete such a short thread ? :/

Probably not, it might be usefull to someone else, besides, I am not sure it will let you delete a thread once there are more than a few replies (I think only mods can do that).
Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Topic Locked

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

Sign in to reply to this topic.