Function/Method Overloading C++: Data type confusion?

前端 未结 7 2506
清酒与你
清酒与你 2021-02-14 18:11

I\'m having some trouble overloading methods in C++. As an example of the problem, I have a class with a number of methods being overloaded, and each method having one parameter

7条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-14 19:00

    The string literal "string" has type const char[] which can be implicity converted to bool. This is the best conversion candidate to one of your overloaded functions although it's not likely to be the most useful one.

    If your intention was to have string literals be handled by the overload taking a std::string, then you need to add an overload taking a const char* and make the implementation call the std::string version.

提交回复
热议问题