I have the following class (header file):
class Kinetics{
double x;
double y;
double z;
public:
Kinetics();
Kinetics(double x_, double y_, double z_);
Kinetics(const Kinetics & obj);
~Kinetics();
double get_x();
void set_x(double x_);
Kinetics operator + (const Kinetics & obj);
Kinetics operator * (double c);
void operator = (const Kinetics & obj);
};
The operators + and * have been implemented (cpp) as:
Kinetics Kinetics::operator + (const Kinetics & obj){
Kinetics aux(x + obj.x, y + obj.y, z + obj.z);
return(aux);
}
and
Kinetics Kinetics::operator * (double c){
Kinetics aux(x * c, y * c, z * c);
return(aux);
}
Contrary to here: no match for operator*
I have declared and included the header file in my main program. I get the following message:
main.cpp:11: error: no match for ‘operator*’ in ‘2.0e+0 * v2’
And I cannot figure out why. The line of code that originates this error (main file) is:
Kinetics v4 = 2.0 * v2;
Any advise would be welcome. Thank you.