Created
December 7, 2014 14:14
-
-
Save pjc0247/86f9524c11095b4e8df2 to your computer and use it in GitHub Desktop.
루비 스타일 C++ getter/setter
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
#define attr_writer(name) \ | |
void set_##name(const decltype(name) &v){ \ | |
this->name = v; \ | |
} | |
#define attr_reader(name) \ | |
decltype(name) get_##name(){ \ | |
return this->name; \ | |
} | |
#define attr_accessor(name) \ | |
attr_reader(name); \ | |
attr_writer(name); | |
/* USAGE | |
class Foo{ | |
public: | |
int v1; | |
float v2; | |
attr_reader(v1); | |
attr_accessor(v2); | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment