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

后端 未结 3 700
滥情空心
滥情空心 2021-01-02 02:54

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

private:
    static const double some_double= 1.0;
         


        
3条回答
  •  再見小時候
    2021-01-02 03:47

    Declare it in the header, and initialize it in one compilation unit (the .cpp for the class is sensible).

    //my_class.hpp
    private:
    static const double some_double;
    
    //my_class.cpp
    const double my_class::some_double = 1.0;
    

提交回复
热议问题