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

标签 c++

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

相关文章:

c++ - 在 Windows 7 下使用 VC++ 进行 LPT 错误 : "External component has thrown an exception."

c++ - sclite(SCTK) `make check`故障,C++/perl/Cygwin,可以安全使用Perl4的东西吗?

c++ - sockets和timer如何互不阻塞地使用?

c++ - C++ 编译器中的 POD 和 VPtr 设计

c++ - std::vector<T>::pop_back 的正式规范

c++ - 每次编译cuda源码时md5sum的值都会变化

c++ - 增量优化掉(Visual C Express 2010)

c++ - 在B类中访问A类的函数f,而f需要访问B的成员变量

c++ - Allegro 和 Code::Blocks 的自动完成功能

c++ - 带有 DirectX 9.0 的多个全屏窗口