Last active
August 19, 2023 02:56
-
-
Save cloudwu/90bba8c5b154722fcb33f772bf9adeba to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// interface | |
struct object { | |
object * create(); | |
void release(); | |
int getState(); | |
}; | |
// implementation | |
struct object_data : object { | |
int state = 0; | |
}; | |
static inline object_data * cast_this(object *p) { return (object_data *)p; } | |
int | |
object::getState() { | |
auto self = cast_this(this); | |
return self->state; | |
} | |
object * | |
object::create() { | |
return new object_data; | |
} | |
void | |
object::release() { | |
auto self = cast_this(this); | |
delete(self); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment