简体   繁体   English

运算符在矩阵中的重载:如何同时重载()和=

[英]operator overloading in matrices: how to overload () and = at the same time

I'm trying to make a class of matrices and try to assign the value at that index like this 我正在尝试制作一类矩阵并尝试像这样在该索引处分配值

M(0,3)=3;

through Operator overloading. 通过运算符重载。 cant figure out how to overload this operator should its prototype be like this? 无法弄清楚如何重载此运算符,其原型应为这样?

void operator()=(int i,int j,int s);//how to overload?

float operator()(int i,int j);//this can be used to get that number form that index.

There is no operator()= . 没有operator()= You want your operator() to return a reference to the element in your matrix. 您希望您的operator()返回对矩阵中元素的引用。 Then you can assign to the referenced element. 然后,您可以分配给所引用的元素。

float& operator()(int i,int j);
const float& operator()(int i, int j) const;

You'll probably also want a const overload that returns a const reference. 您可能还需要const重载,它返回const引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM