Created
June 25, 2011 15:34
-
-
Save shomah4a/1046594 to your computer and use it in GitHub Desktop.
const つけた
This file contains 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 <iostream> | |
#include <boost/function.hpp> | |
class Test | |
{ | |
public: | |
explicit Test(const int x): v(x) | |
{} | |
int add(const int x) const | |
{ | |
return this->v + x; | |
} | |
int operator ()(const int x, const int y) const | |
{ | |
return this->v + x + y; | |
} | |
private: | |
const int v; | |
}; | |
int add(const int x, const int y) | |
{ | |
return x + y; | |
} | |
int main(const int argc, const char* const args[]) | |
{ | |
const auto x = boost::function<int(const int, const int)>(add); | |
const auto y = boost::function<int(const Test&, const int)>(&Test::add); | |
const auto z = boost::function<int(const int, const int)>(Test(10)); | |
std::cout << sizeof(x) << std::endl; | |
std::cout << sizeof(y) << std::endl; | |
std::cout << sizeof(z) << std::endl; | |
std::cout << x(10, 20) << std::endl; | |
std::cout << y(Test(10), 20) << std::endl; | |
std::cout << z(10, 20) << std::endl; | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment