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

前端 未结 7 2502
清酒与你
清酒与你 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 18:48

    The order is of no importance. The problem here is that when you invoke

    Method("string");
    

    you are passing a const char[]. This will be converted to bool implicitly. What you want to do is pass an std::string explicitly:

    Method( std::string("string"));
    

提交回复
热议问题