【发布时间】:2017-04-16 13:04:45
【问题描述】:
class largeNum
{
public:
std::vector<int>& getValue();
private:
std::vector<int> value;
};
这是我使用 getValue() 方法的基类。
std::vector<int>& largeNum::getValue() {
return value;
}
现在尝试在向量中插入值时出现错误:
largeNum operator+(largeNum& summand1, largeNum& summand2) {
largeNum returnNum;
int size = 0;
//adapts the smaller vektor to the larger vektor by resizing him and reversing him so 1 turns into 00...01
if (summand1.getValue().size() > summand2.getValue().size()) {
for (int i = 0; i < (summand1.getValue().size() - summand2.getValue().size()); i++) {
//error happens here
summand2.getValue().insert(0, 0);
}
}
[...]
有趣的是,我可以使用除vector::insert 和vector::erase 之外的所有方法。
它给了我一个错误,说我需要传递两个整数,我正在这样做。
没有重载函数“std::vector<_ty _alloc>::insert [with _Ty=int, _Alloc=std::allocator
]”的实例与参数列表匹配
【问题讨论】:
-
Insert 不采用两个整数作为其参数。 en.cppreference.com/w/cpp/container/vector/insert
-
循环、
operator+、对getValue()的函数调用.. 都无关紧要。下次请发minimal reproducible example,以便您的问题可以重复使用。
标签: c++ algorithm c++11 vector compiler-errors