简体   繁体   中英

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()= . You want your operator() to return a reference to the element in your matrix. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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