Thread: an enum decleration in a header file

  1. #1
    Registered User
    Join Date
    Apr 2019
    Posts
    808

    an enum decleration in a header file

    i have the following enum declared in a header file. and used the labels extensive through out my program rather than testing if current_player is 0 or 1
    Code:
    enum player { PLAYER_WHITE = 0, PLAYER_BLACK = 1 }
    i am trying to write it without the use of global variables (hence all my functions are four foot long) does the above count as a global variable or is it counted as more of a typedef statement.

    coop

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Enumerators are constants, not variables.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2019
    Posts
    808
    so its allowed?? im trying to be strict with myself

  4. #4
    Registered User
    Join Date
    Apr 2019
    Posts
    808
    sorry just read what i said in the first place ie im not allowed global VARIABLES duh!

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Yeah, as long as you give them descriptive names and maybe a prefix specific to your project (especially if you're writing a library), global constants are fine: no one has to be concerned that their values will change from one function call to the next.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 01-17-2015, 04:38 PM
  2. decleration
    By britto116 in forum C Programming
    Replies: 2
    Last Post: 11-13-2009, 07:19 PM
  3. Replies: 30
    Last Post: 06-19-2006, 12:35 AM
  4. Replies: 4
    Last Post: 12-14-2005, 02:21 PM
  5. about decleration?
    By kuwait in forum C++ Programming
    Replies: 5
    Last Post: 10-08-2003, 08:47 AM

Tags for this Thread