Once in a while some functionality has to be conditionally compiled. For example, there's class Logger
that is only used when WITH_LOGGING
macro is #define
d:
// Logger.cpp
#ifdef WITH_LOGGING
#include <Logger.h>
// several hundred lines
// of class Logger
// implementation
// follows
#endif
which is not very convenient - unless the reader scrolls through the file he can't be sure that the matching #endif
is position at the end of file and so the whole file contents is excluded with the #ifdef
. I'd prefre to have something like this:
// Logger.cpp
#ifndef WITH_LOGGING
#GetOutOfThisFile
#endif
#include <Logger.h>
// several hundred lines
// of class Logger
// implementation
// follows
so that it's clear that once the WITH_LOGGING
is not #define
d the compiler just skips the rest of the file.
Is something like that possible in C++?
An easy way to clarify this would be to put the implementation in another file which is included:
file Logger.cpp:
#ifdef WITH_LOGGING
#include <Logger.h>
#include "logger.impl"
#endif
file logger.impl:
// several hundred lines
// of class Logger
// implementation
// follows
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With