我需要做一些逻辑比较并返回一个布尔值答案。逻辑比较==运算符过载
下面是从.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