当我查看 std::back_insert_iterator
http://en.cppreference.com/w/cpp/iterator/back_insert_iterator
它表示将调用容器的 push_back 方法。它如何知道容器是否有 push_back 方法?它是否需要一个扩展任何虚拟类的类,它在哪里定义?
最佳答案
It says the container's push_back method will be called. How does it know if the container has a method of push_back? Does it require a class that extends any virtual class and where is it defined?
不,push_back()
通常不是虚方法。
std::back_insert_iterator
是一个模板,它将在传递的对象上调用 push_back()
。如果缺少该方法,您将遇到编译错误。
关于c++ - C++ 怎么知道容器类有 push_back 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19701294/