Overloading matching weirdness

M

MathStuf

I have a logging function with multiple calling functions that make it
more standard with less coding, but I am getting a weird mis-match
error that outputs the following:

error: call of overloaded `LogSetVar(const char[8], unsigned int&,
const char[5], unsigned int&, const String&)' is ambiguous
note: candidates are: void LogSetVar(const char*, unsigned int, const
char*, long int, const char*) <near match>
note: void LogSetVar(const char*, unsigned int, const
char*, const char*, const char*) <near match>
note: void LogSetVar(const char*, unsigned int, const
char*, long int, const char*, const char*) <near match>
note: void LogSetVar(const char*, unsigned int, const
char*, unsigned int, unsigned int, const char*) <near match>
note: void LogSetVar(const char*, unsigned int, const
char*, unsigned int, bool, const char*) <near match>

My question is why isn't the first one chosen (String has a const
char* operator defined) because all the rest, as I see, aren't close
to matching (last 3 by number, 2nd by type)?
 
?

=?iso-8859-1?q?Erik_Wikstr=F6m?=

I have a logging function with multiple calling functions that make it
more standard with less coding, but I am getting a weird mis-match
error that outputs the following:

error: call of overloaded `LogSetVar(const char[8], unsigned int&,
const char[5], unsigned int&, const String&)' is ambiguous
note: candidates are: void LogSetVar(const char*, unsigned int, const
char*, long int, const char*) <near match>
note: void LogSetVar(const char*, unsigned int, const
char*, const char*, const char*) <near match>
note: void LogSetVar(const char*, unsigned int, const
char*, long int, const char*, const char*) <near match>
note: void LogSetVar(const char*, unsigned int, const
char*, unsigned int, unsigned int, const char*) <near match>
note: void LogSetVar(const char*, unsigned int, const
char*, unsigned int, bool, const char*) <near match>

My question is why isn't the first one chosen (String has a const
char* operator defined) because all the rest, as I see, aren't close
to matching (last 3 by number, 2nd by type)?

Are you sure that std::string has a const char* operator, cause I
can't find any and I've always had to do str.c_str() when a char* or
const char* was expected but I had a string.
 
J

James Kanze

I have a logging function with multiple calling functions that make it
more standard with less coding, but I am getting a weird mis-match
error that outputs the following:
error: call of overloaded `LogSetVar(const char[8], unsigned int&,
const char[5], unsigned int&, const String&)' is ambiguous
note: candidates are: void LogSetVar(const char*, unsigned int, const
char*, long int, const char*) <near match>
note: void LogSetVar(const char*, unsigned int, const
char*, const char*, const char*) <near match>
note: void LogSetVar(const char*, unsigned int, const
char*, long int, const char*, const char*) <near match>
note: void LogSetVar(const char*, unsigned int, const
char*, unsigned int, unsigned int, const char*) <near match>
note: void LogSetVar(const char*, unsigned int, const
char*, unsigned int, bool, const char*) <near match>
My question is why isn't the first one chosen (String has a const
char* operator defined) because all the rest, as I see, aren't close
to matching (last 3 by number, 2nd by type)?

Well, the first one isn't called because it can't be called.
The fourth parameter doesn't match, the result of a conversion
would be a temporary, and you can't bind a temporary to a
non-const reference. The second can't be called, because there
is no conversion unsigned int to char const* (fourth parameter,
again), and the rest can't be called because there aren't enough
arguments. There is no way to legally call any of the
functions.

Because of the way overload resolution is usually implemented,
this often results in an error about an ambiguous call, rather
than a more precise error that none of the available functions
can be called.
 
M

MathStuf

I have a logging function with multiple calling functions that make it
more standard with less coding, but I am getting a weird mis-match
error that outputs the following:
error: call of overloaded `LogSetVar(const char[8], unsigned int&,
const char[5], unsigned int&, const String&)' is ambiguous
note: candidates are: void LogSetVar(const char*, unsigned int, const
char*, long int, const char*) <near match>
note: void LogSetVar(const char*, unsigned int, const
char*, const char*, const char*) <near match>
note: void LogSetVar(const char*, unsigned int, const
char*, long int, const char*, const char*) <near match>
note: void LogSetVar(const char*, unsigned int, const
char*, unsigned int, unsigned int, const char*) <near match>
note: void LogSetVar(const char*, unsigned int, const
char*, unsigned int, bool, const char*) <near match>
My question is why isn't the first one chosen (String has a const
char* operator defined) because all the rest, as I see, aren't close
to matching (last 3 by number, 2nd by type)?

Well, the first one isn't called because it can't be called.
The fourth parameter doesn't match, the result of a conversion
would be a temporary, and you can't bind a temporary to a
non-const reference. The second can't be called, because there
is no conversion unsigned int to char const* (fourth parameter,
again), and the rest can't be called because there aren't enough
arguments. There is no way to legally call any of the
functions.

Because of the way overload resolution is usually implemented,
this often results in an error about an ambiguous call, rather
than a more precise error that none of the available functions
can be called.

--
James Kanze (GABI Software) email:[email protected]
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

So if I made all the parameters const, it would work?

--MathStuf
 
J

James Kanze

I have a logging function with multiple calling functions that make it
more standard with less coding, but I am getting a weird mis-match
error that outputs the following:
error: call of overloaded `LogSetVar(const char[8], unsigned int&,
const char[5], unsigned int&, const String&)' is ambiguous
note: candidates are: void LogSetVar(const char*, unsigned int, const
char*, long int, const char*) <near match>
note: void LogSetVar(const char*, unsigned int, const
char*, const char*, const char*) <near match>
note: void LogSetVar(const char*, unsigned int, const
char*, long int, const char*, const char*) <near match>
note: void LogSetVar(const char*, unsigned int, const
char*, unsigned int, unsigned int, const char*) <near match>
note: void LogSetVar(const char*, unsigned int, const
char*, unsigned int, bool, const char*) <near match>
My question is why isn't the first one chosen (String has a const
char* operator defined) because all the rest, as I see, aren't close
to matching (last 3 by number, 2nd by type)?
Well, the first one isn't called because it can't be called.
The fourth parameter doesn't match, the result of a conversion
would be a temporary, and you can't bind a temporary to a
non-const reference. The second can't be called, because there
is no conversion unsigned int to char const* (fourth parameter,
again), and the rest can't be called because there aren't enough
arguments. There is no way to legally call any of the
functions.
Because of the way overload resolution is usually implemented,
this often results in an error about an ambiguous call, rather
than a more precise error that none of the available functions
can be called.
So if I made all the parameters const, it would work?

Possibly. I don't have the actual signatures here to look at,
so I'm only guessing about the situation from the error message.
If you have problems, it would be better if you posted the exact
code. Not hundreds of lines, of course, but the actual call and
the prototypes for the functions which are being considered. In
this case, perhaps all of the conversion funtions in String as
well, since they also enter into consideration.
 
M

MathStuf

I have a logging function with multiple calling functions that make it
more standard with less coding, but I am getting a weird mis-match
error that outputs the following:
error: call of overloaded `LogSetVar(const char[8], unsigned int&,
const char[5], unsigned int&, const String&)' is ambiguous
note: candidates are: void LogSetVar(const char*, unsigned int, const
char*, long int, const char*) <near match>
note: void LogSetVar(const char*, unsigned int, const
char*, const char*, const char*) <near match>
note: void LogSetVar(const char*, unsigned int, const
char*, long int, const char*, const char*) <near match>
note: void LogSetVar(const char*, unsigned int, const
char*, unsigned int, unsigned int, const char*) <near match>
note: void LogSetVar(const char*, unsigned int, const
char*, unsigned int, bool, const char*) <near match>
My question is why isn't the first one chosen (String has a const
char* operator defined) because all the rest, as I see, aren't close
to matching (last 3 by number, 2nd by type)?
Well, the first one isn't called because it can't be called.
The fourth parameter doesn't match, the result of a conversion
would be a temporary, and you can't bind a temporary to a
non-const reference. The second can't be called, because there
is no conversion unsigned int to char const* (fourth parameter,
again), and the rest can't be called because there aren't enough
arguments. There is no way to legally call any of the
functions.
Because of the way overload resolution is usually implemented,
this often results in an error about an ambiguous call, rather
than a more precise error that none of the available functions
can be called.
So if I made all the parameters const, it would work?

Possibly. I don't have the actual signatures here to look at,
so I'm only guessing about the situation from the error message.
If you have problems, it would be better if you posted the exact
code. Not hundreds of lines, of course, but the actual call and
the prototypes for the functions which are being considered. In
this case, perhaps all of the conversion funtions in String as
well, since they also enter into consideration.

--
James Kanze (GABI Software) email:[email protected]
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

After changing it all to const parameters, it narrows it down to the
ones asterisked below. Here's all of that information:

// Call
LogSetVar("AbilityEffect", id, "val1", v1, StatusShowStr[v1]);
// Types of variables: ^unsigned ^int ^const char*[]

// Conversion
String::eek:perator const char *()
{
return c_str();
}

// Prototypes
// Should be this one
inline void LogSetVar(const char *module, const unsigned id, const
char *var, const long valInt, const char *name = NULL)
// Near match
inline void LogSetVar(const char *module, const unsigned id, const
char *var, const char *valStr, const char *name = NULL)
inline void LogSetVar(const char *module, const unsigned id, const
char *var, const long valInt, const char *valStr, const char *name =
NULL)
// Near match
inline void LogSetVar(const char *module, const unsigned id, const
char *var, const unsigned n, const unsigned d, const char *name =
NULL)
inline void LogSetVar(const char *module, const unsigned id, const
char *var, const unsigned n, bool isNum, const char *name = NULL)

--MathStuf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,123
Latest member
Layne6498
Top