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

问题描述

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

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

class MyClass {
  public:
  private:
     static const int var = 0;            // Option 1
     const static 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.

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.

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

07-22 21:25
查看更多