Search
 
SCRIPT & CODE EXAMPLE
 

CPP

aray of functions in c++

// create array of functions

void a() {
	std::cout << "a
";
}

void b() {
	std::cout << "a
";
}

void c() {
	std::cout << "a
";
}

void d() {
	std::cout << "a
";
}


int main (void) {
	// array of functions
	void (*funcs[4])() = {a, b, c, d};
  	//call the first element of the array
	(*funcs[0])(); // output: "a
"
  
	return 0;
}
Comment

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
"
	
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: 31. Next Permutation leetcode solution in c++ 
Cpp :: array of struct in c++ 
Cpp :: c++ get pointer from unique_ptr 
Cpp :: strring length in c++ 
Cpp :: How to turn an integer variable into a char c++ 
Cpp :: passing structure to function in c++ example 
Cpp :: visual studio getline not working 
Cpp :: c++ changing string to double 
Cpp :: c++ function of find maximum value in an array 
Cpp :: bfs to detect cycle in undirected graph 
Cpp :: c++ constructor call superclass 
Cpp :: stl in c++ 
Cpp :: print in c ++ 
Cpp :: c++ Attribute Parser 
Cpp :: set of vectors c++ 
Cpp :: hello world cc++ 
Cpp :: array copx c++ 
Cpp :: how to write int variable c++ 
Cpp :: put function in cpp 
Cpp :: c++ pop string from vector 
Cpp :: C++ if...else...else if statement 
Cpp :: what is throw in c++ 
Cpp :: how to find factorial of number in c++ 
Cpp :: C++ vector at() method 
Cpp :: the difference between i++ and ++i 
Cpp :: how to take input in 2d vector in c++ 
Cpp :: sort an array in c++ 
Cpp :: floyd algorithm 
Cpp :: print all number between a and b in c++ 
Cpp :: c++ tuple push_back 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =