I've got an exercise to design and implement a class which holds name and age vectors. Further exercises ask me to implement a global == operator overload which will compare two objects. In order to implement that, I have to loop through the lists within the objects and compare element by element.
// Name_pairs.cpp
// Name_pairs class implementation
#include "Name_pairs.h"
#include <algorithm>
using std::cout;
using std::cin;
using std::endl;
using std::string;
int Name_pairs::getSize()
{
return Size;
}
booloperator==( const Name_pairs& a, const Name_pairs& b)
{
bool equal = true;
if( a.getSize() != b.getSize() )
returnfalse;
for( int i = 0; i < a.getSize(); i++ )
return equal;
}
the == operator is obviously incomplete.
The problem I'm having is on the if( a.getSize() != b.getSize() ) line. It doesn't like the use of getSize() with the const references. If I remove the 'const' from the parameters it works, but I'm wondering why it won't work with const parameters.