Qazi
Qazi

Reputation: 13

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.

Upvotes: 1

Views: 120

Answers (1)

AliciaBytes
AliciaBytes

Reputation: 7429

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.

Upvotes: 2

Related Questions