Given the following two constructor signatures, should it be possible to construct a Couple with Couple("George", "Nora")? My compiler complains with the error shown below. If I call it with Couple(std::string("George"), std::string("Nora")) it compiles OK. I’m guessing there’s an issue with the implicit casting which surprises me as I though char* to string would be fine.
class Person
{
public:
Person(const std::string& name);
};
class Couple
{
public:
Coordinate(const Person& p1, const Person& p2, const Optional<Person>& = Optional<Person>());
};
TestCouple.cpp:69: error: no matching function for call to `Couple::Couple(const char[7], const char[5])'
TestCouple.h:24: note: candidates are: Couple::Couple(const Person&, const Person&, const Optional<fox::Person>&)
Indeed, a conversion sequence can’t contain more than one implicit user-defined conversion; the standard specifies this in C++11 12.3/4:
In your case, two would be required (
char const[]tostd::stringtoPerson), and so implicit conversion is not possible.