Jump to content
  • Advertisement

Archived

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

Zygo_#2000

New and This

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

Can someone tell me what "this" is used to in VC++. If you look at the DirectX SDK sample game Donuts, "this" is used very often, but i am not quite sure what it means. Also, if you look at the source for Donuts, you will probably find a statement similar to this somewhere: new = (LPDBLNODE) LocalAlloc( LPTR, sizeof( DBLNODE ) ); How is that possible??? I thought new was used to allocate memory for objects, but here it is used as a pointer. After i saw this a statement like "return = (RECT*)&rc;" would not surprise me *S*. Any help is really appreciated.

Share this post


Link to post
Share on other sites
Advertisement
"this" means "me"


class CFoo {
void Run() {
this.x = 5;
x = 5; // these 2 lines are the same
}
int x;
};


Share this post


Link to post
Share on other sites
this is the pointer to the current object you''re in. When you''re writing your class, you can use this to get a pointer to yourself.

And for the new = (LPDBLNODE) LocalAlloc( LPTR, sizeof( DBLNODE ) );
You''re right! new is used for dynamic memory allocation, but in ++ only.
If you''re not using C++, but only simple C, the new is unknown and then it can be used as a normal variable.

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!