I'd like to print for a debug reasons the namespace of the variable/function it is defined in. I'm trying to use the define directive:
#include <iostream>
#define NS Static
#define MAKESTRING(x) #x
namespace NS {
int global_x = 8;
void print_global_x() {
//print global_x here:
//std::cout << NS << ": " << global_x << std::endl;
std::cout << MAKESTRING(NS) << "::global_x: " << global_x << std::endl;
}
}
but at the #1 line I'm getting a namespace name is not allowed error while with the second approach (line #2) I'm getting just NS::global_x: 8
instead of Static::global_x: 8
How can I correct the code to get the desired result?