3

For my assignment, I was required to make a const static double variable in a class but my compiler gives an error.

const static double long_tarif = 1500.0;//error
const static int long_tarif = 1500;//no error

IntelliSense: a member of type "const double" cannot have an in-class 
initializer

I'm working on visual studio 2013.

  • 4
    It can, it just can't be initialized in the class. – George Apr 10 '17 at 16:16
  • 1
    The error message just says it. The problem is not the declaration but the initialization. The case of the `int` is an exception. –  Apr 10 '17 at 16:17
  • 2
    To enxtend on George's comment, do `struct C { static const double d; };` (header) and `const double C::d = 3.14159;` (source). – YSC Apr 10 '17 at 16:18
  • @i160084AhmedBin You should _probably_ initialize it wherever you implement your class. See YSC's comment – George Apr 10 '17 at 16:31

0 Answers0