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 #defined:
// 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 #defined 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:
file logger.impl: