I know it's better to avoid macros in c++. Use inline functions to replace function-like macros, and constexpr/using to replace const-variable-define macros. But I would like to know if there is one way to replace macro concatenation functionality by some modern c++ techniques.
For example, how to replace the following macros:
#define GETTER_AND_SETTER(name) \
inline void Set##name(int value) \
{ \
m_##name = value; \
}
inline int Get##name() const \
{ \
return m_##name; \
}
then in a class, I can do this for a lot of variables, which makes the code more clean.
GETTER_AND_SETTER(Variable1)
GETTER_AND_SETTER(Variable2)
GETTER_AND_SETTER(Variable3)
...
I have checked here and here, but I don't get the answer. So any idea about this?
Edit: The example of getters/setters is just used to show the idea. Please don't focus on them.