Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <functional>
- class TempWrapper
- {
- public:
- TempWrapper() { /*...*/ }
- TempWrapper(int val) : Value(val) { /*...*/ }
- ~TempWrapper() { /*...*/ }
- TempWrapper & operator = (int val)
- {
- Value = val;
- if (Changed) Changed(Value);
- return *this;
- }
- typedef std::function<void(int)> EvDef;
- EvDef Changed;
- int Value;
- };
- class UsingWrapper
- {
- public:
- TempWrapper MyValue;
- UsingWrapper() { /*...*/ }
- UsingWrapper(int val) : MyValue(val) { /*...*/ }
- ~UsingWrapper() { /*...*/ }
- };
- void onChanged(int value)
- {
- printf("value changed %d\n", value);
- }
- int main()
- {
- UsingWrapper some_value(32);
- some_value.MyValue.Changed = TempWrapper::EvDef(onChanged);
- some_value.MyValue = 77; // With event
- some_value.MyValue.Value = 27; // Without event
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement