Skip to content

Instantly share code, notes, and snippets.

@pjc0247
Created December 7, 2014 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pjc0247/86f9524c11095b4e8df2 to your computer and use it in GitHub Desktop.
Save pjc0247/86f9524c11095b4e8df2 to your computer and use it in GitHub Desktop.
루비 스타일 C++ getter/setter
#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