Overloading C++ STL methods

人盡茶涼 提交于 2019-12-24 00:05:04

问题


How can I overload the STL implementation for methods like find, erase and insert to take varying parameters? I tried to look up the overloading of STL methods but couldn't find any help.


回答1:


You can't overload the methods of a class without editing the code of that class.

Write your own free functions that act as helpers; they would take the relevant container class as the first parameter.

You can inherit from a class and add methods that way, but the std container classes are not designed to be inherited from.




回答2:


You are not allowed to add overloads in the std namespace. Only specialization of functions and algorithms for your own data types are allowed. If you do want a different find, erase, insert... implement a wrapper (out of the std namespace) and use it.

And I would not recommend it either... What kind of overloads do you want to provide?




回答3:


You are not allowed to do this; the standard prohibits it.



来源:https://stackoverflow.com/questions/696320/overloading-c-stl-methods

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!