Skip to content

Instantly share code, notes, and snippets.

@benjamn
Created December 11, 2008 23:54
Show Gist options
  • Save benjamn/34950 to your computer and use it in GitHub Desktop.
Save benjamn/34950 to your computer and use it in GitHub Desktop.
typedef void (A::*Setter)(int val);
void set(A* a, Setter s, int val) {
(a->*s)(val);
}
class A {
int mVal;
void setVal(int val) { mVal = val; }
public:
int getVal() { return mVal; }
static A* create(int val) {
A* a = new A;
set(a, &A::setVal, val);
return a;
}
};
void test() {
ASSERT(A::create(3)->getVal() == 3);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment