I have a URL class that overloads the ==, <, >, and != operators for simple comparison. The URL class has a string data member and some functions to act on the string. The operators work fine when tested with the URL class.
I also have a Page class that has a URL data member. I am trying to overload the same operators in the Page class. Equality in the Page class is based on equality of their respective URLs, so I use the URL class boolean operators in comparing pages. This creates some compiler errors that I cannot figure out. Code for URL operators:
bool URL::operator ==(URL & u) const {
//url is the string instance variable
return url == u.GetURL();
}
Code for Page operators:
bool Page::operator ==(Page & p) const {
//url is the URL instance variable of the Page class
return url == p.GetURL();
}
This produces errors like so:
src/Page.cpp: In member function ‘bool Page::operator==(Page&) const’:
src/Page.cpp:21: error: no match for ‘operator==’ in ‘((const Page*)this)->Page::url == Page::GetURL()()’
inc/URL.h:118: note: candidates are: bool URL::operator==(URL&) const
I predict that it is something dumb that I am forgetting. Will you prove me right?
edit: Const correctness has bitten me in the bum. Thanks for the help.