Logical parameter in parent constructor

This is a discussion on Logical parameter in parent constructor within the C++ Programming forums, part of the General Programming Boards category; I needed to check the parameter from the child's constructor before being sent to the parent. So far I've done ...

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    RColor-0x33>RColor is always false
    do you mean

    RColor-0x33>0

    ?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    then you need to check smthng like

    (RColor > 0x33) ? RColor - 0x33 : 0
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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, 03:39 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 11:03 AM
  4. Constructor with Parameter not Firing
    By BillBoeBaggins in forum Windows Programming
    Replies: 4
    Last Post: 08-26-2004, 03: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21