Take the 2-minute tour ×

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 precompiled 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 redirecct to something else?

Thank you on advance.

share|improve this question
Are you actually including a .cpp? That's not good practice... –  Matteo Italia Dec 5 '12 at 10:07
I'm including only header, it just mechanic mistake:) So can you help me with this question? –  unresolved_external Dec 5 '12 at 10:10

2 Answers 2

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

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

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.

share|improve this answer

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

share|improve this answer

Your Answer


