Skip to content

Instantly share code, notes, and snippets.

@ydm
Created April 5, 2015 13:57
Show Gist options
  • Select an option

  • Save ydm/e6bccb43848c4dbe6a9d to your computer and use it in GitHub Desktop.

Select an option

Save ydm/e6bccb43848c4dbe6a9d to your computer and use it in GitHub Desktop.
#include <functional>
#include <iostream>
#include <typeinfo>
using namespace std;
class Fuck
{
public:
Fuck() {}
virtual ~Fuck() {}
void f() {cout << "this is f()" << endl;}
void s() {cout << "this is s()" << endl;}
};
int main()
{
Fuck *s = new Fuck();
std::function<void (Fuck *)> f1 = &Fuck::f;
std::function<void (Fuck *)> f2 = &Fuck::f;
std::function<void (Fuck *)> s1 = &Fuck::s;
std::function<void (Fuck *)> s2 = &Fuck::s;
void (Fuck::*const *pf1)() = f1.target<void (Fuck::*)()>();
void (Fuck::*const *pf2)() = f2.target<void (Fuck::*)()>();
void (Fuck::*const *ps1)() = s1.target<void (Fuck::*)()>();
void (Fuck::*const *ps2)() = s2.target<void (Fuck::*)()>();
cout << " pf1=" << pf1 << endl
<< "*pf1=" << *pf1 << endl
<< " pf2=" << pf2 << endl
<< "*pf2=" << *pf2 << endl
<< " eq=" << (*pf1 == &Fuck::f) << endl
<< " neq=" << (*pf1 == &Fuck::s) << endl
<< " ps1=" << ps1 << endl
<< "*ps1=" << *ps1 << endl
<< " ps2=" << ps2 << endl
<< "*ps2=" << *ps2 << endl;
(s->**pf1)();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment