0

Can you please help me with following problem? I have a file log.cpp in which is included by different files in the project. I need to declare define in one of those files, which has to affect log.cpp, without actual change in log.cpp or log.h. How can I do this? Solution with pre-compiled header is not acceptable.

And one more question how can I define a static function? I mean if I have CClass::Func called in my code, how can I define it to redirect to something else?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
unresolved_external
  • 1,930
  • 5
  • 30
  • 65

2 Answers2

1

If you want to affect the header, you can put that define before the include:

#define SOMEDEFINE SOMEVALUE
#include log.h
// May want to remove or change our define here
#undef SOMEDEFINE

This is assuming you meant that you include the log.h, as you do not want to include the cpp from other files. The idea with having separate .h and .cpp files is that .h is the interface all compilation units see, whereas the cpp is the code itself, which should only be compiled once, and should not differ depending on from which compilation unit you are referring to it.

Agentlien
  • 4,996
  • 1
  • 16
  • 27
0

With all C++ compilers that I know of, you can #define symbols on the command line. Typically this is done using the -D option.

NPE
  • 486,780
  • 108
  • 951
  • 1,012