Member const 和Member 有什么区别?
《c++ programming lanauage》是这样写的:
10.4.6.2Member Constants
It is also possible to initialize a static integral constant member by adding a constant-expression initializer to its member declaration. For example:
class :Curious {
static const int c1 =7; //ok ,but remember definition
static int c2 =11; // error : not const
const int c3 =13; // error: not static
static const int c4 = f(17); // error: in-class initializer not constant
static const float c5 =7.0; // error: in-class not integral
//....
};
If(and only if) you use an initalized member in a way that requires it to be stored as an object in memory, the member must be (uniquely) defined somewhere. The initializer may not be repeated:
const int Curious::c1; // neccessory, but don't repeat initializer here
const int* p= &Curious::c1; //ok Curious::c1 has been defined
那位高手能帮我解释一下上面的意思嘛?谢谢。
其中,static 和const 为什么一定要连用。
10.4.6.2Member Constants
It is also possible to initialize a static integral constant member by adding a constant-expression initializer to its member declaration. For example:
class :Curious {
static const int c1 =7; //ok ,but remember definition
static int c2 =11; // error : not const
const int c3 =13; // error: not static
static const int c4 = f(17); // error: in-class initializer not constant
static const float c5 =7.0; // error: in-class not integral
//....
};
If(and only if) you use an initalized member in a way that requires it to be stored as an object in memory, the member must be (uniquely) defined somewhere. The initializer may not be repeated:
const int Curious::c1; // neccessory, but don't repeat initializer here
const int* p= &Curious::c1; //ok Curious::c1 has been defined
那位高手能帮我解释一下上面的意思嘛?谢谢。
其中,static 和const 为什么一定要连用。
...全文
相关推荐
C++测试题目(都是非常基础但是很重要的test)
类(class)和结构体(struct)有什么区别?默认情况下,类(class)的成员是私有的,而结构体(struct)的成员是公有的。5. 如何在构造函数中初始化常量成员?
你必须知道的495个C语言问题
{ const char *name; void (*getter)(const void *, FieldName *);};struct FieldInfo fields[] = { {"member1
C语言常见问题集53
**1.13 以下的初始化有什么区别?
C++常见问题解答(解决一些常见疑问)
**结构和类有什么区别?** - 在C++中,结构体(struct)和类(class)非常相似,主要区别在于默认访问级别不同。
你必须知道的495个c语言问题
这样合法和可移植吗?**这种方法通常称为“flexible array member”,是C99引入的一种特性,允许在结构体末尾声明一个数组成员,其大小可以为零。


