How to change the value of a pointer to pointer
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
Everytime you loop you would create a new object in memory. Otherwise, create the object outside the loop and and use the dereference operator:
Is this what you wanted? I don't think i understood..
[edited by - MrBeaner on January 13, 2004 2:48:55 AM]
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]
I think he''s asking how to make ''building'' point to something else. You''d do this:
''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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement