I am working on a program in which I have the struct
Code:
struct molecule {
double x;
double y;
double z;
double const radius = .05;
};
When I compile with g++ without the pedantic flag everything works fine; however, if I use the pedantic flag I get the following error:
Code:
poundcake.h:34: error: ISO C++ forbids initialization of member ‘radius’
poundcake.h:34: error: making ‘radius’ static
poundcake.h:34: error: ISO C++ forbids initialization of member constant ‘radius’ of non-integral type ‘const double’
I have read that you can only use const with types int and enum. Why is this? I don't understand why it would be a bad idea to make a double const.
Also, is there any difference between writing
versus
Thanks in advance.