CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  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

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