Reputation: 197
I want my C++ program to work in one of two modes: normal/debug.
For now I've got some class A
, which I want to replace with class N
when normal mode
or with class D
when debug mode
.
What's the clean way of doing it?
I was thinking about sth like:
// classA.h
#ifdef DEBUG
#include "./classD.h"
#else
#include "./classN.h"
#endif
But how can I easily make this class "compatible" with previus class A
interface?
Upvotes: 0
Views: 97
Reputation: 122657
I cannot help myself but to mention that what you want to do is a little fishy. Unless A
is specifically for debugging I wouldn't want it to be a different class in debug / release builds. As mentioned in a comment, you typically want to debug the code that you later release, not some different code. This sounds like a recipe for confusion.
Having said that, you can make A
an alias to either of the two:
// classA.h
#ifdef DEBUG
#include "./classD.h"
using A = D;
#else
#include "./classN.h"
using A = N;
#endif
Upvotes: 2