Created
December 14, 2015 20:15
c++ functional interface
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <functional> | |
#include <iostream> | |
class Foo { | |
public: | |
Foo(std::function<double()> gauge) { | |
this->_gauge = gauge; | |
} | |
void invoke() { | |
double g = _gauge(); | |
std::cout << "calling gauge returned: " << g << std::endl; | |
} | |
std::function<double()> _gauge; | |
}; | |
void call_it(Foo *foo) { | |
foo->invoke(); | |
} | |
int main() { | |
double val = 4.5; | |
class Foo *f = new Foo([&val] { | |
std::cout << "calling function " << std::endl; | |
return val; | |
}); | |
call_it(f); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment