Static const double in c++

前端 未结 7 426
轮回少年
轮回少年 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:47

    The line const double Shape::pi = 3.14159265; should be in your Shape.cpp file. The header file is for declaring the variables. You can only define a variable once, therefore it must be done in the .cpp. The header file says how to use these variables and functions, the cpp file says what to do.

提交回复
热议问题