c++ - 将非静态 const 数组声明为类成员

标签 c++ arrays class static constants

我们如何将非静态 const 数组声明为类的属性?

以下代码会产生编译错误

'Test::x' : member could not be initialized

class Test
{
public:
    const int x[10];

public:
    Test()
    {
    }
};

最佳答案

您应该阅读this already posted question 。由于无法执行您想要的操作,因此解决方法是使用 std::vector。

关于c++ - 将非静态 const 数组声明为类成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1518965/

相关文章:

c++ - 如何显示gdb以正确显示变量?

c++ - pthread 和 pthread_join 函数的行为

c++ - 数组大小为 200 万的频繁数(适用于 500k 但挂起 200 万?)

python - 使用两个轴排序约束对三维 numpy 数组进行排序

javascript - 为什么这个 React 状态数组不填充对象数据?

C++在函数内分配动态数组

c++ - VS2015 与 VS2013 中的不同优化导致浮点异常

php - PHP 类的版本控制

css - 我应该如何为angularjs中的嵌套对象应用条件类

Python 类装饰器和超过最大递归深度