Advertisement Jump to content


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


How to change the value of a pointer to pointer

This topic is 5485 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
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();

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, you agree to our community Guidelines, Terms of Use, and Privacy Policy. 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!