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 :: clear the input buffer in cpp 
Cpp :: C++ cin cout 
Cpp :: string in cpp 
Cpp :: increment c++ 
Cpp :: log base 10 c++ 
Cpp :: coordinate in 1d array c++ 
Cpp :: c++ clear char array 
Cpp :: remove decimal c++ 
Cpp :: pop_back 
Cpp :: upcasting in c++ 
Cpp :: c++ call by reference 
Cpp :: run cmd command c++ 
Cpp :: find index of element in array c++ 
Cpp :: for c++ 
Cpp :: vector::insert 
Cpp :: To Lower Case leetcode solution in c++ 
Cpp :: cout c++ 
Cpp :: c++ vector resize 
Cpp :: print duplicate characters from string in c++ 
Cpp :: pragma cpp 
Cpp :: c++ int length 
Cpp :: how to find something in a string in c++ 
Cpp :: c++ open file explorer 
Cpp :: ascii cpp 
Cpp :: quicksort geeksforgeeks 
Cpp :: inline c++ 
Cpp :: c++ range based for loop 
Cpp :: hashmap c++ 
Cpp :: string number to integer number C++ 
Cpp :: C++ sum a vector of digits 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =