Switch case

This is a discussion on Switch case within the C++ Programming forums, part of the General Programming Boards category; In a switch case does the quantity have to be an int?...

  1. #1
    Arggggh DeepFyre's Avatar
    Join Date
    Sep 2004
    Posts
    227

    Switch case

    In a switch case does the quantity have to be an int?
    Keyboard Not Found! Press any key to continue. . .

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    It has to be an integral type or an object with a one step conversion to integral type. That doesn't necessarily mean int though, it could be char or long or an enumeration or a class with operator int overloaded. And so on and so forth.
    My best code is written with the delete key.

  3. #3
    Arggggh DeepFyre's Avatar
    Join Date
    Sep 2004
    Posts
    227
    Do you have to do something special to get it to work with a char?
    Keyboard Not Found! Press any key to continue. . .

  4. #4
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Quote Originally Posted by DeepFyre
    Do you have to do something special to get it to work with a char?
    no. post some code.

    Code:
    switch( somechar ) {
      case 'a': ...
    
      case 'b': ---
    
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How can I make this code more elegant?
    By ejohns85 in forum C++ Programming
    Replies: 3
    Last Post: 04-02-2009, 08:55 AM
  2. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 04:42 PM
  3. Replies: 27
    Last Post: 10-11-2006, 04:27 AM
  4. Problems with switch()
    By duvernais28 in forum C Programming
    Replies: 13
    Last Post: 01-28-2005, 09:42 AM
  5. rand()
    By serious in forum C Programming
    Replies: 8
    Last Post: 02-15-2002, 01:07 AM

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