using PI as a const in a header file errors

This is a discussion on using PI as a const in a header file errors within the C++ Programming forums, part of the General Programming Boards category; The header file I have made for my program is full of errors I don't understand and was wondering if ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    6

    Question using PI as a const in a header file errors


    The header file I have made for my program is full of errors I don't understand and was wondering if anyone could explain as I didn't understand the info in the lib help for these errors.

    The compiler comes up with the following errors:
    illegal pure syntax, must be ' =0'
    'PI' : pure specifier can only be specified for functions

    it says this for all of my private variables which are as follows

    const float PI = (float) 3.1416
    flaot radius = 0.0;
    float newRadius = 0.0;

    F.Y.I. - the jist of my program using my header will display the total volume of a sphere, total surface area and a cross sectional area at some point perpendicular to a radial

    Thanks for any and all help!!!

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    24
    Code:
    const float PI = (float) 3.1416 
    flaot radius = 0.0; 
    float newRadius = 0.0;
    well the main thing i can see that you might need to add is a ; after 3.1416

    Code:
    const float PI = (float) 3.1416; 
    flaot radius = 0.0; 
    float newRadius = 0.0;
    maybe? or maybe try taking out the '(float)'
    Good Luck

    -Skeptic

  3. #3
    31173 h4x0r gnu-ehacks's Avatar
    Join Date
    Nov 2001
    Posts
    556
    Hmm...Try this:

    const float PI = 3.1416f;

    Floats either begin or end in f. Forgot which...haven't used floats in a while. I'm a double fan.
    What will people say if they hear that I'm a Jesus freak?
    What will people do if they find that it's true?
    I don't really care if they label me a Jesus freak, there is no disguising the truth!

    Jesus Freak, D.C. Talk

    -gnu-ehacks

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    6
    sorry as far as the ; goes it is there that was a typing error.

    I have tried taken the float out putting () around it putting the () around the 3.14.. value putting f as per the other suggestion and I am still getting the same errors. Any other suggestions??

    Tks

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    61
    Where are you declaring your variables. Because if they' re declared in your class you can't assign them a value right after you declare them, you have to use a function, such as your constructor, to assign them values.

  6. #6
    Unregistered
    Guest
    ...and if they're constants you'll want to make them static, so that they're shared between all instances of your class rather than one for each instance (which would be a waste of space, and time as each one wouldn't have to be initialised).

  7. #7
    Peace
    Join Date
    Aug 2001
    Posts
    1,510
    Because if they' re declared in your class you can't assign them a value right after you declare them, you have to use a function, such as your constructor, to assign them values.
    This is exactly what that error means. You're assigning your variables in the class definition. Take ArseMans advice; It will work.

    Also, a properly decalred floating point variable would look like: "const float PI = 3.1416f;" As gnu-ehacks suggested. The f comes last.
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 02:22 PM
  2. Replies: 8
    Last Post: 04-25-2008, 03:45 PM
  3. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 04:11 PM
  4. Header File Errors...
    By Junior89 in forum C++ Programming
    Replies: 5
    Last Post: 07-08-2007, 01:28 AM
  5. Certain functions
    By Lurker in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2003, 01:26 AM

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