// Can anyone help solve this ??? I tried to use this example as the basis for training... however ...
// I receive the following errors at complie time :
/*
--------------------Configuration: person set 1 - Win32 Debug--------------------
Compiling...
person set 1.cpp
C:\j\hwc2\New Folder\person set 1.cpp(34) : error C2804: binary 'operator <' has too many parameters
C:\j\hwc2\New Folder\person set 1.cpp(35) : error C2804: binary 'operator ==' has too many parameters
Error executing cl.exe.
*/
// Could you help me to resolve this problem. ??? Please ???
#include <set>
#include <conio.h> // for using getch()
#include <string>
// #include <algorithm>
#include <iostream>
//#include <stdlib.h>
using namespace std;
//-------------------- using a multiset
class person
{
protected:
string Lname;
string Fname;
public:
person(): Lname("null", Fname("null" {} //default ctr
person(string Ln, string Fn): Lname (Ln), Fname (Fn) {} //2 arg ctr
bool operator < (const person&, const person&);
bool operator == (const person&, const person&);
void display() const //output person data
{ cout << endl << Lname << ", \t" << Fname << ", \t" << endl; }
};
bool person:perator < (const person& p1, const person& p2) //operator for < comparison
{
if(p1.Lname == p2.Lname)
{ return(p1.Fname < p2.Fname) ? true : false; }
return(p1.Lname < p2.Lname) ? true : false;
}
bool person:perator == (const person& p1, const person& p2) //operator for == comparison
{
return(p1.Lname == p2.Lname && p1.Fname == p2.Fname) ? true : false;
}
//---------------------Now to make it happen. -------------
int main()
{
person p1("Smurf", "Popa"
person p2("Jojojo", "Mojo"
person p3("Willis", "John"
person p4("Willis", "Jolene"
person p5("Snow", "Benjamin"
person p6("MacDonald", "Ronald"
person p7("Silver", "LongJohn"
//created lots of instances to play with.
multiset<person, less<person> > persSet; //iterator to a multiset of persons -- I think ?
multiset<person, less<person> > ::iterator iter;
//put the people into the multiset
persSet.insert(p1);
persSet.insert(p2);
persSet.insert(p3);
persSet.insert(p4);
persSet.insert(p5);
persSet.insert(p6);
persSet.insert(p7);
cout << "\nNumber of entries = " << persSet.size();
iter = persSet.begin();
while (iter != persSet.end() )
(*iter++).display();
string searchLname, searchFname;
cout << "\n\nEnter last name of person to search for : ";
cin >>searchLname;
cout << "\nEnter first name : ";
cin >> searchFname;
//must create such a person's name to use in search
person searchPerson(searchLname, searchFname);
//count the number of occurances
int cntPersons = persSet.count(searchPerson);
cout << "The number of people with that name is : " << cntPersons;
//show all the names that match
iter = persSet.lower_bound(searchPerson);
while(iter != persSet.upper_bound(searchPerson))
(*iter++).display();
cout << endl;
getch ();
return 0;
}
// I receive the following errors at complie time :
/*
--------------------Configuration: person set 1 - Win32 Debug--------------------
Compiling...
person set 1.cpp
C:\j\hwc2\New Folder\person set 1.cpp(34) : error C2804: binary 'operator <' has too many parameters
C:\j\hwc2\New Folder\person set 1.cpp(35) : error C2804: binary 'operator ==' has too many parameters
Error executing cl.exe.
*/
// Could you help me to resolve this problem. ??? Please ???
#include <set>
#include <conio.h> // for using getch()
#include <string>
// #include <algorithm>
#include <iostream>
//#include <stdlib.h>
using namespace std;
//-------------------- using a multiset
class person
{
protected:
string Lname;
string Fname;
public:
person(): Lname("null", Fname("null" {} //default ctr
person(string Ln, string Fn): Lname (Ln), Fname (Fn) {} //2 arg ctr
bool operator < (const person&, const person&);
bool operator == (const person&, const person&);
void display() const //output person data
{ cout << endl << Lname << ", \t" << Fname << ", \t" << endl; }
};
bool person:perator < (const person& p1, const person& p2) //operator for < comparison
{
if(p1.Lname == p2.Lname)
{ return(p1.Fname < p2.Fname) ? true : false; }
return(p1.Lname < p2.Lname) ? true : false;
}
bool person:perator == (const person& p1, const person& p2) //operator for == comparison
{
return(p1.Lname == p2.Lname && p1.Fname == p2.Fname) ? true : false;
}
//---------------------Now to make it happen. -------------
int main()
{
person p1("Smurf", "Popa"
person p2("Jojojo", "Mojo"
person p3("Willis", "John"
person p4("Willis", "Jolene"
person p5("Snow", "Benjamin"
person p6("MacDonald", "Ronald"
person p7("Silver", "LongJohn"
//created lots of instances to play with.
multiset<person, less<person> > persSet; //iterator to a multiset of persons -- I think ?
multiset<person, less<person> > ::iterator iter;
//put the people into the multiset
persSet.insert(p1);
persSet.insert(p2);
persSet.insert(p3);
persSet.insert(p4);
persSet.insert(p5);
persSet.insert(p6);
persSet.insert(p7);
cout << "\nNumber of entries = " << persSet.size();
iter = persSet.begin();
while (iter != persSet.end() )
(*iter++).display();
string searchLname, searchFname;
cout << "\n\nEnter last name of person to search for : ";
cin >>searchLname;
cout << "\nEnter first name : ";
cin >> searchFname;
//must create such a person's name to use in search
person searchPerson(searchLname, searchFname);
//count the number of occurances
int cntPersons = persSet.count(searchPerson);
cout << "The number of people with that name is : " << cntPersons;
//show all the names that match
iter = persSet.lower_bound(searchPerson);
while(iter != persSet.upper_bound(searchPerson))
(*iter++).display();
cout << endl;
getch ();
return 0;
}