Hi,
main.cpp

  vector<Employee>e;

    e.push_back(Employee("Hawaii",100));
    cout<<endl;
    e.push_back(Employee("Scotland",20));
    cout<<endl;
    e.push_back(Person("Saga",30));
    cout<<endl;

        Employee e1;     //created an object

        sort(e.begin(),e.end());

    e1.show(e);

Employee.h

  bool operator<(const Employee& e1,const Employee& e2);

Employee.cpp

      bool operator<(const Employee& e1,const Employee& e2)
{
    return e1.getName() < e2.getName();
}

With this code it is just sorting only the first 2 objects and displaying the output as Hawaii 100,Saga 30,Scotland 20.

Please let me know what is the mistake in my code.

Recommended Answers

All 2 Replies

Where's the problem here, your objects seem to be sorted appropriately to me.

If you tell us what you expect the program to do and how what it's actually doing differs from the expected, we may be able to help you.

Until you establish your intent though, we can not help you because we don't know what behavior is considered correct and therefore do not know what behavior is considered incorrect.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.