我有一個自定義類,並且正在嘗試爲=創建運算符重載函數。不幸的是,我得到的錯誤沒有指向特定的行或錯誤,我只是得到以下錯誤。1嘗試超載時出現無法解析的外部錯誤=運算符
解析外部符號 「公共:整數__thiscall序列::大小(無效)常量」 在函數引用「公共(大小@ @@序列QBEHXZ?):無效__thiscall序列::運算=(類序列常量& )」(?? 4sequence @@ QAEXABV0 @@ Z)
它是在文件Sequence2.obj線1.這不是我編輯文件時,我有點不確定的錯誤是在什麼樣的功能。
Sequence2.cpp
void sequence::operator=(const sequence & source)
{
if (size() <= source.size()) {
delete[] data;
data = new value_type[source.size()];
current_index = -1;
used = 0;
}
else {
delete[] data;
data = new value_type[source.size() * 2];
current_index = -1;
used = 0;
}
for (int i = 0; i < source.size(); i++)
{
data[i] = source.data[i];
used++;
current_index++;
}
}
大小功能,只需返回序列的大小。在Main.cpp上,我只有以下幾點。
sequence test; // A sequence that we’ll perform tests on
sequence test2;
test.insert(33);
test.insert(35);
test.insert(36);
test2 = test;
該錯誤與'operator ='本身無關。編譯器(鏈接器)告訴你,你忘了定義'size()'函數。 'size()'的定義在哪裏? – AnT