lundi 30 novembre 2020

How to call a random function of a class in c++?

I am trying to create a command-line game in C++. I am new to it and just started learning. My game consists of a player class and a dragon class. The classes are declared in separate header files. What I would like to know is, if there is a way to call a random function of a class after declaration.
Like

// ignore the includes
class foo{
    public:
        string name = "foo";
        foo(string name){
            this->name = name;
        }

        void func1(){
            //some code
        }

        void func2(){
            //some code
        }

        void func3(){
            //some code
        }
}


/////
//main.cpp
#include <iostream>
#include "foo.h"

int main(){
    foo bar("hello");
    //call a random function like func1, func2, func3;
    return 0;
}



Aucun commentaire:

Enregistrer un commentaire