Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Operator overloading of "basic" classes

Hello I want to multiply a matrix by a number at left, something like : N=a*M where a is a number.

If i wanted to multiply at right i would have simply overloaded the operator * in my matrix class. But what shall I do in this case ? Can I overload the operator * of float even if it's a "default" class ? (I'm not even sure it's a class)

like image 277
user2370139 Avatar asked Sep 07 '26 04:09

user2370139


1 Answers

You would have to define the function in terms of the other. For example:

Matrix operator *(float x, Matrix const& m)
{
    return m * x;
}
like image 158
David G Avatar answered Sep 09 '26 18:09

David G