I am trying to create a library management system. I am getting a few errors which I don\'t understand. I am using Eclipse in Mac os.
My main code is:
#i
Game *search( char gameName[]);
DVD *search( char dvdName[]);
Book *search( char bookName[]);
the parameters for search
in these 3 cases have exactly the same type. The only difference is the return type.
You cannot overload only on return type, as which function is called is determined by parameters, not by what you assign it to.
The easy solution is calling it searchDVD
and searchGame
and searchBook
. At both declaration and implementation.
The crazy solution would then involve adding this class:
struct deferred_search {
Library* lib;
char const* name;
operator DVD*()const {
return lib->searchDVD(name);
}
operator Book*()const {
return lib->searchBook(name);
}
operator Game*()const {
return lib->searchGame(name);
}
}
and in Library
:
deferred_search search( char const* name ) { return {this, name}; }
which is a somewhat obscure technique to do overloading on return type. I would advise against it -- just call the functions searchTYPE
.