我需要做一些邏輯比較並返回一個布爾值答案。邏輯比較==運算符過載
下面是從.cpp文件的代碼:
bool MyString::operator==(const MyString& other)const
{
if(other.Size == this.Size)
{
for(int i = 0; i < this.Size+1; i++)
{
if(this[i] == other[i])
return true;
}
}
else
return false;
}
這裏是從的main.cpp文件名爲:
if (String1 == String4)
{
String3.Print();
}
else
{
String4.Print();
}
這裏是有編譯錯誤,我得到:
error: request for member `Size` in `this`, which is of non-class type `const MyString* const`
error: no match for `operator[]` in `other[i]`
'如果(這[一] ==等[1]) 迴歸真實;'這將在以後導致你的問題。想想你在那裏做什麼。 – chris 2012-04-28 22:59:39
這實際上是我現在得到的唯一錯誤。我想要做的就是比較兩個字符串的內容。我怎麼可能做到這一點,而不必重載[]運算符呢? – user1363061 2012-04-29 00:01:10