Hey fellas (and ladies?), sooooo given the following implementation, I'm getting the error below:
1 2 3 4 5 6 7 8 9 10
friendbooloperator< (const intEntry& lhs, const intEntry& rhs);
//this is inside the class
bool intEntry::operator< (const intEntry& lhs, const intEntry& rhs)
//this is in the same file, outside the class. The compiler catches here
error: 'bool intEntry::operator<(const intEntry&, const intEntry&)'
must take exactly one argument|
//this is the error
(intEntry is the class)
would you guys have any idea why the compiler is throwing this error?
No inline has nothing to do with it being a friend.
It's like this... #include is basically a copy/paste function. So if you #include a header in multiple cpp files, everything in that header gets copy/pasted into each of those cpp files.
As a result, if you have any function bodies in your header file... the linker will get confused and will see this as the same function having two different bodies in different areas of the program. By marking the function as inline, we avoid that issue.
So when you put a function body in a header ... that is when you use inline. (for a overly simplified explanation).
Again... this has nothing to do with the function being a friend of this class.
when operator overloading,
it may be a member function if you have one parameter only.
If you need two parameters then you mustn't make it a member function.
And that means you must make it a 'friend' of your class so it can access the important information in the private section of your class. hope that helps