C++ Why the call is ambigous? -
class myclass { int arr[100]; public: void *get(long i, void* const to) const; void *get(long i, bool nog); void *tstfn(void* const to) { return get(0l,to); } };
gcc -wall says:
dt.cpp: in member function ‘void* myclass::tstfn(void*)’: dt.cpp:6:49: warning: iso c++ says these ambiguous, though worst conversion first better worst conversion second: [enabled default] dt.cpp:4:9: note: candidate 1: void* myclass::get(long int, void*) const dt.cpp:5:9: note: candidate 2: void* myclass::get(long int, bool)
both function calls require type conversion:
- calling
void*
function requires addingconst
qualiferthis
- calling
bool
function requires convertingto
void*
bool
.
so, overload resolution rules, neither "better" match other, , call considered ambiguous.
perhaps can add const
second function; perhaps remove first (although i'd prefer not to); perhaps can explicit type conversion of either this
or to
force preferred override.
Comments
Post a Comment