I have a function in the header file:
template <int line>
inline void log() {}
And then I try this trick to make it easier to use:
#define LOG_LINE log<__LINE__>()
And then in the .cpp file I:
void main()
{
LOG_LINE;
}
And it looks like it works the way I would like. I get the line from the .cpp file, not the line in which it is LOG_LINEdeclared in the .h file. But I don’t understand how it works. Does preprocessing do dual-processing C ++, leaving behind special macros such as __LINE__for the second pass? Is this a portable (standard) behavior? Should I expect this to work with all major C ++ compilers? So far I have only tried MSVC.
source
share