|
-
September 8th, 2008, 07:26 AM
#1
Conditional derivation from base class based on preprocessor ifdef and ifndef
In our application we have the option of using color management or not. We are using a special library for color management.
This is controlled by preprocessor definitions.
Code:
#ifdef COLOR_MANAGEMENT
Code:
#ifndef COLOR_MANAGEMENT
Our application should be compilable and build if COLOR_MANAGEMENT is not defined and the corresponding source not included.
I have created a wrapper class to include this color management functionality.
Now other classes can be derived from this wrapper class if they wish to provide color management functionality.
But if COLOR_MANAGEMENT is not defined it would be useless to derive from this wrapper base class. So I need some kind of conditional inclusion of base class. But I think this is not possible.
I think templates could be the solution. But I am not sure. Could you all please suggest how I should be approaching this problem?
Instead of deriving from the wrapper class. I could just embed the wrapper class.
Code:
#ifdef COLOR_MANAGEMENT
#include "CMWrapper.h"
#endif
class MyClass
{
#ifdef COLOR_MANAGEMENT
CMWrapper m_ColorMgntWrapper
#endif
};
But I don't like this solution.
So can templates rescue me. If yes then how I go about using it in my case?
Thanks
Please help.
Last edited by miteshpandey; September 8th, 2008 at 07:30 AM.
If there is no love sun won't shine
-
September 8th, 2008, 07:40 AM
#2
Re: Conditional derivation from base class based on preprocessor ifdef and ifndef
Isn't this what you are looking for?
Code:
class MyClass
#ifdef COLOR_MANAGEMENT
: public CMWrapper
#endif
{
};
Nobody cares how it works as long as it works
-
September 8th, 2008, 08:05 AM
#3
Re: Conditional derivation from base class based on preprocessor ifdef and ifndef
Thanks zerver didn't know if that was allowed
If there is no love sun won't shine
-
September 8th, 2008, 08:16 AM
#4
Re: Conditional derivation from base class based on preprocessor ifdef and ifndef
Everything that expands to valid C++ code is allowed with preprocessor directives.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|