Reputation: 2873
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.
Upvotes: 2
Views: 373
Reputation: 361362
Well, std::vector
member functions begin()
and end()
returns iterator of type std::vector<T>::iterator
, or `std::vector<T>::const_iterator
, depending on whether the vector object is const
or non-const. Whatever it is, the iterator type is not defined by you. Overloading ==
in your class sqrlist
does 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.
Upvotes: 3