我是 C++ 新手。
我想要有 5 个数组作为字段的类。这些数组的大小应动态初始化。
我已经编写了一些代码,但这不正确知道:
class ParsedData {
public:
int generators_count;
double mean_arr[generators_count];
double variance_arr[generators_count];
int amount_of_numbers_to_generate_arr[generators_count];
int intervals_count;
double interval_begins_arr[intervals_count];
double interval_ends_arr[intervals_count];
};
ParsedData::ParsedData(int _generators_count, double[] _mean_arr, double[] _variance_arr, int[] _amount_of_numbers_to_generate_arr,
int _intervals_count, double[] _interval_begins_arr, double[] _interval_ends_arr) {
generators_count = _generators_count;
mean_arr = _mean_arr;
variance_arr = _variance_arr;
amount_of_numbers_to_generate_arr = _amount_of_numbers_to_generate_arr;
intervals_count = _intervals_count;
interval_begins_arr = _interval_begins_arr;
interval_ends_arr = _interval_ends_arr;
}
编译错误日志:
z01.cpp:53:9: error: invalid use of non-static data member ‘ParsedData::generators_count’
z01.cpp:54:21: error: from this location
z01.cpp:53:9: error: invalid use of non-static data member ‘ParsedData::generators_count’
z01.cpp:55:25: error: from this location
z01.cpp:53:9: error: invalid use of non-static data member ‘ParsedData::generators_count’
z01.cpp:56:43: error: from this location
z01.cpp:57:9: error: invalid use of non-static data member ‘ParsedData::intervals_count’
z01.cpp:58:32: error: from this location
z01.cpp:57:9: error: invalid use of non-static data member ‘ParsedData::intervals_count’
z01.cpp:59:30: error: from this location
z01.cpp:62:56: error: expected ‘,’ or ‘...’ before ‘_mean_arr’
z01.cpp:62:1: error: prototype for ‘ParsedData::ParsedData(int, double*)’ does not match any in class ‘ParsedData’
z01.cpp:51:7: error: candidates are: ParsedData::ParsedData(const ParsedData&)
z01.cpp:51:7: error: ParsedData::ParsedData()
z01.cpp: In function ‘ParsedData load_input_data()’:
z01.cpp:102:62: error: no matching function for call to ‘ParsedData::ParsedData(int&, double [(((sizetype)(((ssizetype)generators_count) + -1)) + 1)], double [(((sizetype)(((ssizetype)generators_count) + -1)) + 1)], int [(((sizetype)(((ssizetype)generators_count) + -1)) + 1)], int&, double [(((sizetype)(((ssizetype)intervals_count) + -1)) + 1)], double [(((sizetype)(((ssizetype)intervals_count) + -1)) + 1)])’
z01.cpp:102:62: note: candidates are:
z01.cpp:51:7: note: ParsedData::ParsedData()
z01.cpp:51:7: note: candidate expects 0 arguments, 7 provided
z01.cpp:51:7: note: ParsedData::ParsedData(const ParsedData&)
z01.cpp:51:7: note: candidate expects 1 argument, 7 provided
有什么方法可以解决这个问题?