I am currently working on overloading the == operator for my linked list. I have the operator in my header set up like the following:
class sqrlst
{
public:
std::vector<int> vlist;
bool operator == (iterator const & rhs )
{
return this->iter == rhs.iter;
};
I then created a method in my header file with the following code
void test()
{
bool flag;
if (vlist.begin()==vlist.begin())
{
flag=true;
}
};
};
However when this method is called it does not go to my overloaded == operator function when it hits the if statment. When I put the debug point on the overload function it says that the line will not be reached.
Any tips or suggestions are greatly appreciated. Thanks!
EDIT: vlist is a list of ints.
Well,
std::vectormember functionsbegin()andend()returns iterator of typestd::vector<T>::iterator, or`std::vector<T>::const_iterator, depending on whether the vector object isconstor non-const. Whatever it is, the iterator type is not defined by you. Overloading==in your classsqrlistdoes nothing. The overload==should be a member of vector’s iterator class, which you’re not allowed to edit.Also note that vector’s iterator class has already overloaded
==and!=operators. So when you compare iterators using==, it is invoking a member function of vector’s iterator class.