Thread: Can I use "#define" within a class?

  1. #1
    INSANE INSIDE ekosix's Avatar
    Join Date
    May 2010
    Location
    Rio de Janeiro, Brazil
    Posts
    44

    Question [SOLVED] Can I use "#define" within a class?

    Hi guys...

    I was searching about it on the net, and I realized the best way to declare constants within a class is by using "enum".

    But I haven't found anything about using the preprocessor command "#define".

    Is it possible to use it anywhere I want?

    Thanks.
    Last edited by ekosix; 12-07-2011 at 08:35 AM.

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    In a C++ program you should be using the "const" qualifier instead of #define. ie: const int your_variable_name = 100;


    Jim

  3. #3
    INSANE INSIDE ekosix's Avatar
    Join Date
    May 2010
    Location
    Rio de Janeiro, Brazil
    Posts
    44
    But why I should be using "const" instead of "#define"?

  4. #4
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by ekosix View Post
    But why I should be using "const" instead of "#define"?
    [29] Newbie Questions / Answers Updated! , C++ FAQ

  5. #5
    INSANE INSIDE ekosix's Avatar
    Join Date
    May 2010
    Location
    Rio de Janeiro, Brazil
    Posts
    44
    Thanks guys!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. the operator "="error in class "String"
    By boyhailong in forum C++ Programming
    Replies: 9
    Last Post: 07-27-2011, 08:39 PM
  2. How define template with "exception" cases?
    By 6tr6tr in forum C++ Programming
    Replies: 4
    Last Post: 04-29-2008, 12:55 AM
  3. Replies: 4
    Last Post: 11-20-2006, 03:36 PM
  4. "itoa"-"_itoa" , "inp"-"_inp", Why some functions have "
    By L.O.K. in forum Windows Programming
    Replies: 5
    Last Post: 12-08-2002, 08:25 AM
  5. "CWnd"-"HWnd","CBitmap"-"HBitmap"...., What is mean by "
    By L.O.K. in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 07:59 AM

Tags for this Thread