I'm writing a program under MS Visual C++ 6.0 (yes, I know it's ancient, no there's nothing I can do to upgrade). I'm seeing some behavior that I think is really weird. I have a class with two constructors defined like this:
class MyClass
{
public:
explicit MyClass(bool bAbsolute = true, bool bLocation = false) : m_bAbsolute(bAbsolute), m_bLocation(bLocation) { ; }
MyClass(const RWCString& strPath, bool bLocation = false);
private:
bool m_bAbsolute;
bool m_bLocation;
};
When I instantiate an instance of this class with this syntax: MyClass("blah")
, it calls the first constructor. As you can see, I added the explicit
keyword to it in the hopes that it wouldn't do that... no dice. It would appear to prefer the conversion from const char *
to bool
over the conversion to RWCString
, which has a copy constructor which takes a const char *
. Why does it do this? I would assume that given two possible choices like this, it would say it's ambiguous. What can I do to prevent it from doing this? If at all possible, I'd like to avoid having to explicitly cast the strPath
argument to an RWCString
, as it's going to be used with literals a lot and that's a lot of extra typing (plus a really easy mistake to make).