Created
December 11, 2008 23:54
-
-
Save benjamn/34950 to your computer and use it in GitHub Desktop.
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
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