小编LIM*_*IMA的帖子

operator overloading [] [] 2d array c ++

我有一个2D数组,我想定义一个函数,它返回用户使用运算符重载的索引值.换一种说法:

void MyMatrix::ReturnValue()
{
    int row = 0, col = 0;
    cout << "Return Value From the last Matrix" << endl;
    cout << "----------------------------------" << endl;
    cout << "Please Enter the index: [" << row << "][" << col << "] =" << ((*this).matrix)[row][col] << endl;
}
Run Code Online (Sandbox Code Playgroud)

该操作((*this).matrix)[row][col]应该返回一个int.我不知道如何建立operator [][].
或者,我可以连接几个调用operator [],但我没有成功,因为第一次调用该操作将返回int*,第二次将返回int,它强制构建另一个运算符,我不想去做.

我能做什么?谢谢,

c++ arrays 2d operator-overloading operator-keyword

5
推荐指数
2
解决办法
3315
查看次数

标签 统计

2d ×1

arrays ×1

c++ ×1

operator-keyword ×1

operator-overloading ×1