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

Thread: optionally enable the params

  1. #1
    Join Date
    May 2015
    Posts
    326

    optionally enable the params

    Hello ,
    In the following class

    Code:
    class A
    {
    :::::::::::::::::
    
    private:
           legacy fields...
    [COLOR="#FF0000"]	
    new fields
    };
    The class already exists, and new params (in red)were added as part. Now based on some variable, i want to make the new params optional. Is there anyway to use the same format, and use these fields as optional. Because this class is used for many pixels, so it is very imp in keeping the memory optimal.
    Whatabout putting these under union ? will it help.

    thankyou
    pdk
    Last edited by pdk5; September 22nd, 2020 at 05:16 AM.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,825

    Re: optionally enable the params

    what is wrong for you to derive a new class and add these new members into it?
    Victor Nijegorodov

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,289

    Re: optionally enable the params

    Now based on some variable, i want to make the new params optional.
    As in defined or not? - sorry, can't be done at run-time. You can do it at compile time but then every instance of the class will either have or not have.

    As Victor points out, this is usually done by deriving a new class with the extra members/functions etc.

    Code:
    class PixelCovCellInfoNew : public PixelCovCellInfo {
        // Constructor(s) etc
    
        unsigned short	m_traf_encoded_rank;
        short		m_traf_ricefactor;	// mB
        unsigned char	m_traf_delayspread;	// dBns  (dB nanoseconds)
        int			m_traf_angularspread;   // mBrad (mB radians)
    };
    Last edited by 2kaud; September 21st, 2020 at 07:25 AM.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.7.7)

  4. #4
    Join Date
    May 2015
    Posts
    326

    Re: optionally enable the params

    Thanks a lot Victor and kaud.

    This is burried somewhere deep in the legacy code. The issue is that the number of pixels is ususally huge .

    So for each pixel , we store the above legacy fields .

    But new to new feature we had to add those 4 new fields. But then, since this is causing lot of memory , we want to make this feature optional by having a variable input through the GUI.

    If variable is set, then only we try the new fields. otherwise, we donot want to waste memory and donot want to store the new fields for each pixel.

    I guess, your suggestions should work. I now need to dig deeper, to find where and how pixel info is allocated and use this new class instead.

    thanks a lot

  5. #5
    Join Date
    May 2015
    Posts
    326

    Re: optionally enable the params

    Now moved the new fields into derived class
    Last edited by pdk5; September 22nd, 2020 at 05:18 AM.

  6. #6
    Join Date
    May 2015
    Posts
    326

    Re: optionally enable the params

    Very strange, when i try to assign the base class pointer to object of new derived type:


    I get error saying "cannot be assigned to an entity of type" !


    This issue is resolved now .. very sorry.. the issue was new derived class was put above the old class in .h . And it didnot complain there, but was complaining in cpp !!!
    Last edited by pdk5; September 22nd, 2020 at 05:18 AM.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)