I am working on a program in which I have the struct
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:struct molecule {
double x;
double y;
double z;
double const radius = .05;
};
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.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’
Also, is there any difference between writing
versusCode:const int x
Thanks in advance.Code:int const x