How to define a const double inside a class's header file?

zebra picture zebra · Dec 9, 2011 · Viewed 11.6k times · Source

Inside the header file of my class, I am trying the following and getting compiler complaints:

private:
    static const double some_double= 1.0;

How are you supposed to actually do this?

Answer

Kerrek SB picture Kerrek SB · Dec 9, 2011

In C++11, you can have non-integral constant expressions thanks to constexpr:

private:
    static constexpr double some_double = 1.0;