Selective performance of Class n function/method



  • Good afternoon! I'm studying with+, interested in the function of an arbitrary number of n times from console or other method. e.g. functions:

    void func1(){...};
    int func2(params){...; return int r;}
    

    And I want to go to the consulate by running func1 20 times, run func2 10, etc., how can I do that?



  • int foo(){
        return 4;
    }
    
    int bar(int a){
        return a*a;
    }
    
    int main(int argc, char** argv){
        if(argc < 3) return 1;
    
        if(strcmp(argv[1], "foo") == 0){ //Выбираем имя функции
            std::vector<int> returnValues; //Вектор возвращаемых значений
            for(int i=0; i<atoi(argv[2]); ++i){
                returnValues.push_back( foo() );
            }
        }
    
        if(strcmp(argv[1], "bar") == 0){ //Выбираем имя функции
            if(argc < 4){
                std::cout << "Недостаточно аргументов для функции bar!" << std::endl;
            }
            std::vector<int> returnValues; //Вектор возвращаемых значений
            for(int i=0; i<atoi(argv[2]); ++i){
                returnValues.push_back( bar(atoi(argv[3])) );
            }
        }
    }
    

    Next, after compilation (g++ source.cpp -o myRun() May be called upon to perform the function: myRun foo 4 - It's a function. foo 4 times; myRun bar 7 3 challenges the function bar Seven times, moving in. 3

    If there is a need to do something about reset values, they will lie in. returnValues (meaning to do something with them only inside the program).

    The code didn't check, so there might be a little syntax error.


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2