Let\'s say I have the following class X
where I want to return access to an internal member:
class Z
{
// details
};
class X
{
std::vec
Is it cheating to use the preprocessor?
struct A {
#define GETTER_CORE_CODE \
/* line 1 of getter code */ \
/* line 2 of getter code */ \
/* .....etc............. */ \
/* line n of getter code */
// ^ NOTE: line continuation char '\' on all lines but the last
B& get() {
GETTER_CORE_CODE
}
const B& get() const {
GETTER_CORE_CODE
}
#undef GETTER_CORE_CODE
};
It's not as fancy as templates or casts, but it does make your intent ("these two functions are to be identical") pretty explicit.