【发布时间】:2013-03-23 16:11:26
【问题描述】:
我有 CMatrix 类,其中是指向值数组的“双指针”。
class CMatrix {
public:
int rows, cols;
int **arr;
};
我只需要通过键入来访问矩阵的值:
CMatrix x;
x[0][0] = 23;
我知道如何使用:
x(0,0) = 23;
但我真的需要换一种方式。任何人都可以帮助我吗?请?
最后感谢大家的帮助,我是这样做的...
class CMatrix {
public:
int rows, cols;
int **arr;
public:
int const* operator[]( int const y ) const
{
return &arr[0][y];
}
int* operator[]( int const y )
{
return &arr[0][y];
}
....
感谢您的帮助,我真的很感激!
【问题讨论】:
-
C++中没有operator[][],你也编不出来... -
“我真的需要这样做”为什么?是作业吗?
-
只重载数组项的[]操作符
-
@BartekBanachewicz 因为这是学校作业,用精确的术语...
标签: c++ matrix overloading operator-keyword