// A classic test class:
class A
{
public:
A(char const*);
};
// A class with a dodgy interface:
class B
{
public:
void f(A const&)
{
}
void f(bool)
{
}
};
void test()
{
B b;
b.f("");
}
b.f("") will call B::f(bool).
Note that declaring A(char const*) explicit makes no difference. Evidently,
the compiler chooses the build in convertion first anyway.
MS VC7 will output a warning:
warning C4800: 'char *' : forcing value to bool 'true' or 'false'
(performance warning)
My colleges and I mostly turn a blind eye as soon as we see "(performance
warning)". In this particular case, I'd rather get a more meaningfull
warning e.g: "Are you sure you want us to do this?". "us" because I reckon
there has been more than 1 programmer coding the compiler...
I realize that most of the problem lies with the bool parameter since just
about anything on the face of this earth can be converted to a bool. The
example above is minimalistic. In our real code, we have bool IN-params all
over the place and many have default values which makes it all the worse.
So, just a wish!
Cheers,
Conrad Weyns
MW Ron - 27 Aug 2004 18:15 GMT
I'll submit this as a feature request,
Thanks for pointing it out.
>// A classic test class:
>class A
[quoted text clipped - 41 lines]
>Cheers,
>Conrad Weyns

Signature
Metrowerks Community Forum is a free online resource for developers
to discuss CodeWarrior topics with other users and Metrowerks' staff
-- http://www.metrowerks.com/community --
Ron Liechty - MWRon@metrowerks.com - http://www.metrowerks.com