Run Code
|
Code Wall
|
Users
|
Misc
|
Feedback
|
About
|
Login
|
Theme
|
Privacy
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
1
Please
log in
to post a comment.
next greater palindrome
euler tour (by pure theory)
at.cpp
HeapSort
Hi
gal2
Problem: binary
Programa 3(Creo que ya esta)
remove_if_30-Seconds-of-C++
array, loop, function examples
Please log in to post a comment.