静态常量与常量静态 [英] static const versus const static

查看:91
本文介绍了静态常量与常量静态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白我的C ++类中这两个语句之间的区别:

I do not understand the difference between these two statements in my C++ class:

class MyClass {
  public:
  private:
     const static int var = 0;            // Option 1
     static const int var = 0;            // Option 2
};

b / w选项1和选项2有什么区别?他们都编译。

What is the difference b/w Option 1 and Option 2?? They both compile.

推荐答案

它们的含义完全相同。

They mean exactly the same thing. You're free to choose whichever you think is easier to read.

在C中,您 应该放置 static 在开始,但它还不需要。我不确定C ++在这方面是否遵循C。

In C, you should place static at the start, but it's not yet required. I'm not sure if C++ followed C in this regard.


6.11.5存储类说明符

6.11.5 Storage-class specifiers

1声明之外的存储类说明符的位置
声明中的说明符是一个过时的特性。

1 The placement of a storage-class specifier other than at the beginning of the declaration specifiers in a declaration is an obsolescent feature.

这篇关于静态常量与常量静态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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