c++ - Why my token-pasting usage doesn't work? -
i made declaration below.
#define func_dec(f) inline void f##(){} class myclass { public: func_dec(a); func_dec(b); };
after preprocessing, expected class looked like:
class myclass { public: inline void a(){}; inline void b(){}; };
while actually, got compiling errors
#20 identifier "a" undefined #20 identifier "b" undefined warnings description resource path location type #891-d omission of explicit type nonstandard ("int" assumed)
can tell me what's wrong declaration? thank much.
in case, don't need use ##
operator.
#define func_dec(f) inline void f(){}
is fine.
it concatenation operator, useful kind of case:
#define func_dec(f) inline void funcdec##f(){} // ^^^^^^^^^^
who expanded as:
inline void funcdeca(){} // func_dec(a)
just say: code works fine on visual studio.
Comments
Post a Comment