The preprocessor does not require any declared C ++ characters to be evaluated to do their job.
This is pure text processing , so defining a macro as
#define PRINT_DEBUG_INFO(a) {cout << "Info: " << a << endl;}
and expanding it like
#include <iostream> void foo { int a = 5; PRINT_DEBUG_INFO(a); }
will become
// All the literal stuff appearing in <iostream> void foo { int a = 5; {cout << "Info: " << a << endl;}; }
Therefore, when defining or expanding a macro, nothing is checked against the correct C ++ syntax.
These statements will be further processed by the C ++ compiler, which will complain about cout , which is not declared in the global scope.
To fix this, declare your macro as
#define PRINT_DEBUG_INFO(a) {std::cout << "Info: " << a << std::endl;}
πάντα ῥεῖ
source share