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

前端 未结 7 2505
清酒与你
清酒与你 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:50

    As Charles already pointed out, this happens due to an unwanted implicit conversion. If you want to avoid that, use a std::string constructor: Method(std::string("string")); or cast it to std::string:

    Method(static_cast("string"));
    

    However, the order of your declarations isn't important. Also check your spelling of the word "parameter" ;)

提交回复
热议问题