【发布时间】:2020-01-11 09:04:41
【问题描述】:
到目前为止,我知道我可以使所有结构成员const。但是我可以在某个地方写一次const,然后让所有成员都转向const吗?
换句话说,我希望所有结构实例都是const,即使我忘记在变量声明中添加const 修饰符。
const struct Foo {}
由于const can only be specified for objects and functions错误,上述方法不起作用;
【问题讨论】:
-
这比
struct Foo {}; const Foo f;有什么优势? -
简答:否。
-
@Quentin 请看第二段(现在添加)
-
术语:
const是“限定符”而不是“修饰符”。
标签: c++ struct types constants type-declaration