【发布时间】:2012-03-04 06:16:31
【问题描述】:
我正在尝试在 MSVS2010 控制台应用程序中使用多维数组,并且我需要访问二维数组的成员。我将数组实例化为
Thing::Thing(int _n){
// size of the array
this.m = _n;
thing = new int*[m];
for(int ii = 0; ii < m; ii++){
thing[ii] = new int[m];
}
}
这工作正常。虽然当我去做一个 operator= 或 operator== 时,它们都使用类似的结构:
Thing& Thing::operator=(const Thing & _thing){
for(int ii = 0; ii < m; ii++){
for(int jj = 0; jj < m; jj++){
thing[ii][jj] = _thing[ii][jj]; //error thrown on this line
}
}
return *this;
}
这会引发 2 个错误
binary "[": 'const Thing' does not define this operator or a conversion to a type acceptable to the predefined operator
IntelliSense: no operator"[]" matches these operands
这没有意义,因为它是一个 int 类型的数组,并且“[]”运算符没有改变,更不用说错误突出显示仅将其置于:
_thing[ii][jj];
我可以不用赋值运算符,但我需要比较运算符才能具有功能。
【问题讨论】:
标签: c++ visual-studio-2010 multidimensional-array