Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


C++ question (excuse me)

This topic is 6351 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Guest Anonymous Poster

Does it show up like this?


the "->" works to dereference pointers for classes... so if Aircraft were a class we''d create a pointer to an instance of it

Aircraft* AircraftObject = NULL;
AircraftObject = new Aircraft(whatever);

so you can reference all the member data and methods like this:

They work the same way. All "->" is for is to be a more intuitive way to work with pointers and to save you typing one character. Also makes code a lot easier to read...

Share this post

Link to post
Share on other sites
^ Yeah, what (s)he said. :D

Additionally, you can also think of it in the same way as you think of arrays, because the operator [] is a dereferencing tool just like the operator ->. The [] operator is more versatile (hence why it''s used in arrays -- simple integers are easy to understand) as you can easily move down a chain of similarly-sized things, whereas -> simply points to the first, leaving cycling through memory addresses as the programmer''s responsibility (which is how standard library iterators work, by adding sizeof(THE_DATA_TYPE) to the value of the pointer).

So essentially, something->somethingElse is identical to something[0].somethingElse... Of course, some times it''s better and more readable to use the [] notation, and sometimes the -> notation.

~ Dragonus

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!