Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Function to m_function
#include <iostream> #include <functional> using namespace std; class Computer{ function<int(Computer, int, int)> compute; int Add(int a, int b){ return a + b; } int Sub(int a, int b){ return a - b; } int Mul(int a, int b){ return a * b; } int Div(int a, int b){ return a / b; } public: Computer() = delete; Computer(char op){ switch (op) { case '+': compute = &Computer::Add; break; case '-': compute = &Computer::Sub; break; case '*': compute = &Computer::Mul; break; case '/': compute = &Computer::Div; break; default: throw string("op error! must be [+,-,*,/]"); } } int Compute(int a, int b){ return compute(*this, a, b); } }; int main(int argc, char* argv[]) { Computer c('+'); int a = c.Compute(12, 13); cout << a; return 0; }
run
|
edit
|
history
|
help
2
water drop/ water land
Eratosfen final
Defining Class Members
no copy elision
GRAPH DFS & BFS
Podejrzana karteczka :0
printAllPathsInMatrix
asa
Suma
Dulce enredo p1