如何在类的头文件中定义一个const double? [英] How to define a const double inside a class's header file?

查看:197
本文介绍了如何在类的头文件中定义一个const double?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的类的头文件中,我尝试以下和获得编译器投诉:

  private:
static const double some_double = 1.0;

你应该怎么做呢?

$ b>

$ b

在C ++ 11中,可以有非整数常量表达式,因为 constexpr
$ b

  private:
static constexpr double some_double = 1.0;


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?

解决方案

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

private:
    static constexpr double some_double = 1.0;

这篇关于如何在类的头文件中定义一个const double?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆