Jump to content
  • Advertisement

Archived

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

penetrator

C++ question (excuse me)

This topic is 6265 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

Advertisement
Guest Anonymous Poster

Does it show up like this?

AircraftObject->HorizontalSpeed++;

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:
(*AircraftObject).HorizontalSpeed++;
or
AircraftObject->HorizontalSpeed++;

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!