Link to home
Start Free TrialLog in
Avatar of TrueIdiot
TrueIdiot

asked on

Constant definitions in a class

I tried to write a circle class and everything worked excepts for the statement:

const double PI = 3.14159;

VC++ gave me some errors that made no sense at all:

C:\Windows\Desktop\My C++\Classes\MyClasses\circle.h(36) : error C2258: illegal pure syntax, must be '= 0'
C:\Windows\Desktop\My C++\Classes\MyClasses\circle.h(36) : error C2252: 'PI' : pure specifier can only be specified for functions
C:\Windows\Desktop\My C++\Classes\MyClasses\CircleImp.cpp(43) : error C2065: 'PI' : undeclared identifier

why can't I declare a constant???
ASKER CERTIFIED SOLUTION
Avatar of vadik
vadik

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of frogger1999
frogger1999

or for a static memeber

class foo{

    public:

    foo();

    protected:
    static const double bar;
};

const double foo::bar = 1.0;