How can I select a specific function overload?

前端 未结 2 1428
刺人心
刺人心 2021-01-27 19:03

I want to pass an overloaded operator to a function, which can\'t figure out which of the two overloads it should use.

// This works, not overloaded:
chai.add(ch         


        
2条回答
  •  遇见更好的自我
    2021-01-27 19:34

    The following may help you to choose one overload of map::operator[]

    static_cast<
        std::string& (std::map::*)(const std::string&)>(
            &std::map::operator []);
    

    Or with a typedef:

    using MyMap = std::map;
    
    static_cast(&MyMap::operator []);
    //          ReturnType    Class     params
    

提交回复
热议问题