Static const double in c++

前端 未结 7 461
轮回少年
轮回少年 2021-01-02 07:54

Is this the proper way to use a static const variable? In my top level class (Shape)

#ifndef SHAPE_H
#define SHAPE_H

class Shape
{
public:

    static cons         


        
7条回答
  •  执念已碎
    2021-01-02 08:33

    If you have a way to add C++0x flag to your compiler, you would've been able to do:

    ifndef SHAPE_H
    #define SHAPE_H
    
    class Shape
    {
    public:
    
        static constexpr double pi = 3.14159265;
    private:
        double originX;
        double originY;
    };
    
    #endif
    

    In C++0x you are able to use const expressions to types other than integral ones. This enables you to declare and define in place your constant variable.

提交回复
热议问题