CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2003
    Location
    kathmandu, nepal
    Posts
    1,570

    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

  2. #2
    Join Date
    Jun 2002
    Location
    Stockholm, Sweden
    Posts
    1,641

    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

  3. #3
    Join Date
    Apr 2003
    Location
    kathmandu, nepal
    Posts
    1,570

    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

  4. #4
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Conditional derivation from base class based on preprocessor ifdef and ifndef

    Everything that expands to valid C++ code is allowed with preprocessor directives.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured