Like Tree4Likes
  • 3 Post By jimblumberg
  • 1 Post By manasij7479

Can I use "#define" within a class?

This is a discussion on Can I use "#define" within a class? within the C++ Programming forums, part of the General Programming Boards category; Hi guys... I was searching about it on the net, and I realized the best way to declare constants within ...

  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 07:35 AM.

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


    Jim
    ekosix, Elysia and Elkvis like this.

  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
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,498
    Quote Originally Posted by ekosix View Post
    But why I should be using "const" instead of "#define"?
    [29] Newbie Questions / Answers ..Updated!.., C++ FAQ
    ekosix likes this.
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  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, 02: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, 07: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, 06:59 AM

Tags for this Thread


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