Jump to content
  • Advertisement

Archived

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

How to change the value of a pointer to pointer

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

Hi: say i have the following code: while(true) { Building* building = new Building(); } a new Building object is created, and the memory of it is assigned to building and the pointer building itself is in another memory address, say, A. I am just wondering how can I change the value A everytime it makes loop Cheers

Share this post


Link to post
Share on other sites
Advertisement
Everytime you loop you would create a new object in memory. Otherwise, create the object outside the loop and and use the dereference operator:


Building* building = new Building();
while(true)
{
building->dosomething();
}


Is this what you wanted? I don't think i understood..

[edited by - MrBeaner on January 13, 2004 2:48:55 AM]

Share this post


Link to post
Share on other sites
I think he''s asking how to make ''building'' point to something else. You''d do this:

Building* building = new Building( );
Building* other = new Building( );
building = other;

''building'' now points to the second building and the first building is in memory but cannot be accessed anymore, so that''s bad code and you''d never do that. But pointers can be reassigned, like I just did.

~CGameProgrammer( );

-- Post screenshots of your projects. 100+ posts already in the archives.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!