==操作符重载作为成员函数如何书写
==操作符重载作为成员函数怎么书写?
这是作为普通函数的代码,帮我改写成成员函数吧
------解决方案--------------------
------解决方案--------------------
将第一个参数视为this不就解决了吗。
------解决方案--------------------
bool operator==(const Vector& a,const Vector& b)
{
bool yes = true;
if(a.size != b.size)
{
yes = false;
}
else
{
int index = 0;
int s = a.get_size();
while (index<s && a[index] == b[index])
{
++index;
}
if(index < s)
{
yes = false;
}
}
return yes;
}
这是作为普通函数的代码,帮我改写成成员函数吧
------解决方案--------------------
friend bool Vector::operator==(const Vector & a);
bool Vector::operator==(const Vector & a)
{
bool yes = true;
if(a.size != this->size)
{
yes = false;
}
else
{
int index = 0;
int s = a.get_size();
while (index<s && a[index] == this[index])
{
++index;
}
if(index < s)
{
yes = false;
}
}
return yes;
}
------解决方案--------------------
将第一个参数视为this不就解决了吗。
------解决方案--------------------