I am currently working on creating an overloaded function for the == operator. I am creating an hpp file for my linked list and I can't seem to get this operator working in the hpp file.
I currently have this:
template <typename T_>
class sq_list
{
bool operator == ( sq_list & lhs, sq_list & rhs)
{
return *lhs == *rhs;
};
reference operator * () {
return _c;
};
};
}
I get about 10 errors but they pretty much repeat as errors:
C2804: binary 'operator ==' has too many parameters
C2333:'sq_list::operator ==' : error in function declaration; skipping function body
C2143: syntax error : missing ';' before '*'
C4430: missing type specifier - int assumed. Note: C++ does not support default-int
I've tried changing things around but I constanly get the same errors as above
Any tips or assistance on this is greatly appreciated.
The member operator only has one argument, which is the other object. The first object is the instance itself:
template <typename T_>
class sq_list
{
bool operator == (sq_list & rhs) const // don't forget "const"!!
{
return *this == *rhs; // doesn't actually work!
}
};
This definition doesn't actually make sense, since it just calls itself recursively. Instead, it should be calling some member operation, like return this->impl == rhs.impl;
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With