Static const double in c++

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

    It happens because you can't define Shape::pi more than once. It's defined once when you include Shape.h in Shape.cpp, and then again every other time you use Shape.h in another cpp file. When you go to link you program together the linker will barf because of multiple definitions.

提交回复
热议问题