Thread: using PI as a const in a header file errors

  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
    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
    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, 01:22 PM
  2. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  3. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  4. Header File Errors...
    By Junior89 in forum C++ Programming
    Replies: 5
    Last Post: 07-08-2007, 12:28 AM
  5. Certain functions
    By Lurker in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2003, 01:26 AM