Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

array of Methods c++

// create array of Methods
class Msgs {
  private :

    void debug( void ) {
    	std::cout << "debug
";
    }
  
    void info( void ) {
    	std::cout << "info
";
    }
  
    void warning( void ) {
    	std::cout << "warning
";
    }
  
    void error( void ) {
    	std::cout << "error
";
    }

  public :

  	void    showMSG( void );
			
};

void Harl::showMSG() {
	/* [harl::debug] is a member function and you need 
  	 a pointer to member in order to invoke it. */
	void (Harl::*functions[4])() = { &Harl::debug, &Harl::info, &Harl::warning, &Harl::error };

	(this->*functions[1])(); // output: "info
"
	
}
 
PREVIOUS NEXT
Tagged: #array #Methods
ADD COMMENT
Topic
Name
3+9 =