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\circ le.h(36) : error C2258: illegal pure syntax, must be '= 0'
C:\Windows\Desktop\My C++\Classes\MyClasses\circ le.h(36) : error C2252: 'PI' : pure specifier can only be specified for functions
C:\Windows\Desktop\My C++\Classes\MyClasses\Circ leImp.cpp( 43) : error C2065: 'PI' : undeclared identifier
why can't I declare a constant???
const double PI = 3.14159;
VC++ gave me some errors that made no sense at all:
C:\Windows\Desktop\My C++\Classes\MyClasses\circ
C:\Windows\Desktop\My C++\Classes\MyClasses\circ
C:\Windows\Desktop\My C++\Classes\MyClasses\Circ
why can't I declare a constant???
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
class foo{
public:
foo();
protected:
static const double bar;
};
const double foo::bar = 1.0;