Skip to content

Instantly share code, notes, and snippets.

@YukiSakamoto
Created August 26, 2012 10:05
Show Gist options
  • Save YukiSakamoto/3476781 to your computer and use it in GitHub Desktop.
Save YukiSakamoto/3476781 to your computer and use it in GitHub Desktop.
Macros that defines accessors of class-instance variables.
#define ATTR_READER(name,type) \
public: \
type get_ ## name(void) { \
return this-> name; \
}
#define ATTR_WRITER(name,type) \
public: \
void set_ ## name(type new_val) { \
this-> name = new_val; \
}
class Hogehoge {
private:
int a;
ATTR_READER(a,int)
ATTR_WRITER(a,int)
public:
};
#include <stdio.h>
int main(void)
{
Hogehoge a;
a.set_a(100);
printf("%d\n", a.get_a());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment