如何在构造函数中使用参数初始化结构数组?现在我有这个代码:
struct roundMatrix {
private:
int **matrix;
public:
roundMatrix(int teamsNumber) {
matrix = new int*[teamsNumber];
for(int i=0;i<teamsNumber;i++) {
matrix[i] = new int[teamsNumber];
}
}
int addPartners(int first, int second) {
if(matrix[first][second] == -1 && matrix[second][first] == -1) {
matrix[first][second] = 0;
matrix[second][first] = 0;
}
else {
return -1;
}
return 0;
}
};
...
然后我需要用参数初始化roundMatrix数组:
roundMatrix rounds[roundsNumber](teamsNumber);
我得到一个错误:
variable-sized object 'rounds' may not be initialized
还有一个问题。如何使用结构和构造函数参数初始化向量?