在 C++ 中声明常量数组值
例如我有:
int boo[8];
boo[1] = boo[3] = boo[7] = 4;
boo[0] = boo[2] = 7;
boo[4] = boo[5] = boo[6] = 15;
我应该如何将其输入为常量值?我看到类似的问题,但对我没有帮助。
编辑: 还有一个问题,如果索引为 0 1 3 4 5 6 7 的 boo 是常量,但 boo[2] 不是常量呢?有可能做到吗?
For example I have:
int boo[8];
boo[1] = boo[3] = boo[7] = 4;
boo[0] = boo[2] = 7;
boo[4] = boo[5] = boo[6] = 15;
How I should type it as constant values? I saw similar question but it didn't help me.
EDIT:
One more question what about if boo with indexes 0 1 3 4 5 6 7 is constant but boo[2] is not? is it possible to do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是您要找的吗?
获取指向数组中一项的非常量指针,如下所示:
Is this what you are looking for?
Get a non-const pointer to one entry in the array like this:
一个不太优雅的解决方案可能是:
另一种解决方案可能是:
One not so elegant solution may be:
Another solution may be: