I was hoping that somebody could tell me why this works the way it does.
I have a class that has the data members as private and in order to access them I have public functions that return this data, as such:
I have used an operator overload function to compare the ISBN numbers and return a bool. Effectively I want to pass in the two books without modifying them and do the comparison, however the function won't allow me to add const at the beginning of the parameter. This is the function I wrote:
As you can see it is calling the display_ISBN function, which I think is where the problem lies, but I am not sure why. When I pass by non-const it works as expected.
bool operator==(const Book& a, const Book&b)
return a.display_ISBN() == b.display_ISBN();
The error I get when passing by const reference is
error C2662: 'Book::display_ISBN' : cannot convert 'this' pointer from 'const Book' to 'Book &'
I would appreciate some advice as to why this is?