Invoking a destructor

Hello, beginner programmer here and I'm needing help. I'm making myself a small program with a class labeled "Player" what I'm trying to do is make sort of a short story, what I want to do is say for example, "You're surrounded by enemies, what's your next move? A. "blah blah" B. "blah blah" C. "blah blah". and if they select the wrong one I want it to invoke the destructor, killing the player and outputting something like "player killed..". So my questions are, how could I go about this? I need a small example code or explanation on how I could invoke this within the users input. I need to know how to invoke the destructor if the player selects the C choice, for example.

And also, would using a class for this be more efficient? Or would this come into context if I more to actually make a game was actually playable that had an interface and art? Would using classes be appropriate for that as well? I know I could just say something like "Output 3 choices" then use cases for what the user selects for each one of those.. but; I want your opinion on why I SHOULDNT do that and should use classes. (if I should) I know this thread was very long. If anyone's up to helping me, thank you very much!!!

It's best if you do not directly mess around with destructors.

Create a class for the player with a flag to indicate if the player is alive or dead.
1
2
3
4
5
6
7
struct player
{
    std::string name ;
    bool alive = true ; // set to false to kill the player

    void kill() { alive = false ; std::cout << "player '" << name << "' killed\n" ; }
}; 


If you are not familiar with vectors and iterators, this would be Greek to you.
http://coliru.stacked-crooked.com/a/b438bdc0e1f667f4
You may want to read: https://cal-linux.com/tutorials//STL.html
Yes this does look a bit forgein to me considering I've never been introduced to "struct" or vectors and iterators.. I'll read what you've provided, thank you very much! Something like this is exactly what I was looking for. You're very helpful.
Topic archived. No new replies allowed.