Thread: Logical parameter in parent constructor

  1. #1
    In the Land of Diddly-Doo g4j31a5's Avatar
    Join Date
    Jul 2006
    Posts
    476

    Logical parameter in parent constructor

    I needed to check the parameter from the child's constructor before being sent to the parent. So far I've done this:

    Code:
    CListBox::CListBox(std::string name, SDL_Surface *screen, CTTFont* theFont,
    	Sint16 xx, Sint16 yy, Sint16 width, 
    	Uint8 ROptColor, Uint8 GOptColor, Uint8 BOptColor, //option text color
    	Uint8 RColor, Uint8 GColor, Uint8 BColor, //button color
    	Uint8 RArrowColor, Uint8 GArrowColor, Uint8 BArrowColor) //arrow color
     : CGUI_Object(name, screen, GUI_LISTBOX,
    	xx,yy,width, 24,
    	(RColor-0x33>RColor ? 0x00:RColor-0x33),(GColor-0x33>GColor ? 0x00:GColor-0x33),(BColor-0x33>BColor ? 0x00:BColor-0x33))
    But that code didn't work. FYI, the parameters were unsigned chars so I needed to check whether the parameters can become negative or not. If it can, it will be inputed as zero in the parent class.

    The question is it possible to include a logical expression in a parent's constructor? If it is, how do I do it?

    Thanks.

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    RColor-0x33>RColor is always false
    do you mean

    RColor-0x33>0

    ?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    In the Land of Diddly-Doo g4j31a5's Avatar
    Join Date
    Jul 2006
    Posts
    476
    Quote Originally Posted by vart
    RColor-0x33>RColor is always false
    do you mean

    RColor-0x33>0

    ?
    Actually yes. But because the parameters are unsigned, "RColor-0x33>0 " will always be true even if it was supposed to be false because RColor (and other parameters) can't become negative.

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    then you need to check smthng like

    (RColor > 0x33) ? RColor - 0x33 : 0
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    In the Land of Diddly-Doo g4j31a5's Avatar
    Join Date
    Jul 2006
    Posts
    476
    Quote Originally Posted by vart
    then you need to check smthng like

    (RColor > 0x33) ? RColor - 0x33 : 0
    Right, why didn't I think of that? Such an elementary mistake and yet I didn't realized it. Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  4. Constructor with Parameter not Firing
    By BillBoeBaggins in forum Windows Programming
    Replies: 4
    Last Post: 08-26-2004, 02:17 PM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM