【发布时间】:2020-05-01 20:29:14
【问题描述】:
我目前正在制作我的自定义矢量容器,以便更好地了解真正的 STL 容器。我面临“插入”功能的问题。
这是我的向量容器中“插入”的两个原型。
// 1
template <typename T, typename Alloc>
void vector<T, Alloc>::insert(iterator position, size_type n, const value_type &val)
// 2
template <typename T, typename Alloc>
template <class InputIterator>
void vector<T, Alloc>::insert(iterator position, InputIterator first, InputIterator last)
当我尝试在 main.cpp 中使用插入函数时,如下所示,
int main() {
ft::vector<int> my;
my.insert(my.begin(), 5, 6); <-- it calls second proto.
return (0);
}
我打算调用第一个原型,但它调用了第二个用于迭代器参数的原型...... 你能解释一下它为什么会发生以及如何解决它吗?
【问题讨论】: