We used this type of macro in our code:
// convenience macros for implementing field setter/getter functions
#ifndef CREATE_GET_SET
#define CREATE_GET_SET(PREFIX, FIELD_NAME,FIELD_DATATYPE) \
protected:\
FIELD_DATATYPE PREFIX ## FIELD_NAME;\
public:\
inline FIELD_DATATYPE get ## _ ## FIELD_NAME(void) const\
{ \
return(PREFIX ## FIELD_NAME); \
} \
inline void set ## _ ## FIELD_NAME(FIELD_DATATYPE p) \
{ \
PREFIX ## FIELD_NAME = p; \
}
#endif
within a class/structure you would define a variable:
CREATE_GET_SET(_, id, unsigned int);
This would define your variable and create the generic getter/setter for the code. It just makes for cleaner, consistent code generation for get/set. Sure, you can write it all out, but that's a lot of boilerplate type code NOTE: this is just one of a couple macros. I didn't post them all. You wouldn't handle say "char *" this way (where you want the set to strncpy or strcpy the data). This was just a simple demo of what you could do with a macro and some simple types.