Hi, I have recently been learning about classes and operator functions. and while working these things into examples i have come across a problem. I have solved it but i really need an explantion as to why my solution worked.
I have a multiplication function :
Code:
Point mult(int n, const Point &other);
Point mult(int n, const Point &other) {
Point newpoint;
newpoint.x = other.x * n;
newpoint.y = other.y * n;
return newpoint;
}
which i call in the following operator function:
Code:
friend Point operator*(int n, const Point &other) {return mult(n, other);}
after trying to compile this i got this error :
29 C:\Dev-Cpp\Exercises\pointclass\main.cpp cannot call member function `Point Point::mult(int, const Point&)' without object
Not knowing what this means i just mucked around and made the mult function a friend, and it worked. Im just wondering why this worked. By giving the mult function two arguments did i make it global or something? , and making it a friend gave it access to what it needed?
Plz explain, lol
Thx in Advance