gpt4 book ai didi

c++ - C++ 怎么知道容器类有 push_back 函数?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:57:20 25 4
gpt4 key购买 nike

当我查看 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com