Jump to content
  • Advertisement

Archived

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

colinisinhere

->?

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

I was reading the Quake 3 source the other day, and I see a lot of re->wc.FatGuy[T_EATME] kind of stuff. But i don''t understand this -> i see everywhere, it obviously is usful, what does it do?

Share this post


Link to post
Share on other sites
Advertisement

class MyClass
{
public:
MyClass(){};
~MyClass(){};

myFunction1();
myFunction2();
};

MyClass *Test;
Test = new MyClass;

Test->myFunction1();


The class is MyClass and when we create Test we use an asterisk(*) to make it a pointer. Then we use new to allocate the memory to Test. Now when you want to use Test you use the -> to access it''s memebers.

James Simmons
MindEngine Development
http://medev.sourceforge.net

Share this post


Link to post
Share on other sites
No you must use -> otherwise it assumes the structure or class is located at the memory address of the pointer.

Put it this way, you have 5 blocks [] [] [] [] []

You have a struct in block 5, so it looks like this:

[] [] [] [] [blah]

Now you make a pointer to blah, the pointer is located elsewhere in memory

[] [5] [] [] [blah]

The 5 in there tells you that you are pointing to the 5th block, which contains the struct

If you use the "." instead of "->", then the computer will think that the 2nd block contains a struct, when in reality it contains the location of a struct. Things wont workout so well, using the "->" tells the computer to look at the number in block 2, and that number is the location of the struct.


Hope that didn''t confuse you too much.



It''s not reality that''s important, but how you perceive things.

Share this post


Link to post
Share on other sites
its just a short method of saying (*p).stuff ,it helps to have an understanding of basic pointers to ints,doubles,chars,before you do pointers to structs and classes.

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!