Skip to main content
gamedev.net
🔒 Locked

~destructors

Started by The Alchemist Jul 6, 2000 at 10:34 PM 7 replies 600+ views
Original Post
The Alchemist
The Alchemist
finaly a programming question from me... i´m building a console for a rpg(text based for now). on this console i use C++ classes to make the battle caracters, so in the constructor i make all that efects that a character do when he enter in a fight:
    
caracter()
{
  // do initialization stuff

   cout << the goblin appears!!!!!;
}
    
but i want do the same with the the destuctors: [source] ~caracter() { cout << the goblin was destroyed!!; } but how i can destroy a object?? i know that program do this automatic when it exit the from the funtion or whoever it is doing ends(of curse i´m talking of non-global objects) but how i do it myself??? ============ Why she did that?? becouse she knows that you loved her. what?? i can be i a half-mystics and all but i´m still a woman!! -Zozma and lady Asellus. Saga Frontier
"Everything works out in the end, if it doesn't then it is not the end"
Pouya
Pouya
    
delete character;


- pouya
--------------
The trick to flight is to throw yourself at the ground and miss!!!
The Alchemist
The Alchemist
pouya: but the delete must be use with new!! i don´t wanna deal with pointers( well, not on this moment) don´t there another way??

anom: well, i was a idiot in that post ,sorry , i should not be so rude, since you probaly know more of programming that i do.
but you don´t get my point. i put that cout thing in my code just becouse is a simple thing and is just a demo, but in the real thing that i willing to do, i will not make any logic i just will tell the main game loop " hey ,the goblin was destroyed, you can start to make his dead animation" get it?

"Everything works out in the end, if it doesn't then it is not the end"
Pouya
Pouya
can''t you just put that in a method and call is Destroy() and call everything you want it to be gone?

p.s. why do you hate pointers? they''re the best feature in c++

- pouya / FOO!!!
--------------
The trick to flight is to throw yourself at the ground and miss!!!
Armitage
Armitage
You can also do
    
{
caracter c;
}

which should invoke the default ctor, and then the dtor.
Simply put it in a scope with the same lifespan. But it would be better if you simply used new/delete.
A polar bear is a rectangular bear after a coordinate transform.
The Alchemist
The Alchemist
i don´t hate pointers, but i´m just trying to make a demo to see if my idea works so i want to make the code clean and simple, but i quess that no have other way...

============
Why she did that??
becouse she knows that you loved her.
what?? i can be i a half-mystics and all but i´m still a woman!!
-Zozma and lady Asellus. Saga Frontier
"Everything works out in the end, if it doesn't then it is not the end"

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.