How to change the value of a pointer to pointer

Started by
1 comment, last by 00702000744 20 years, 3 months ago
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
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]
------------------------------------------VOTE Patrick O'GradyWrite in Presidential CandidateThe Candidate who Cares.
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.
~CGameProgrammer( );Developer Image Exchange -- New Features: Upload screenshots of your games (size is unlimited) and upload the game itself (up to 10MB). Free. No registration needed.

This topic is closed to new replies.

Advertisement