Created
August 26, 2012 10:05
-
-
Save YukiSakamoto/3476781 to your computer and use it in GitHub Desktop.
Macros that defines accessors of class-instance variables.
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
#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