Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7442911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:14:52+00:00 2026-05-29T11:14:52+00:00

Good evening, experts I am working on the exercise in programming in generic way.

  • 0

Good evening, experts

I am working on the exercise in programming in generic way. I understood how to to sort the different objects with different data types, however I am struggling how to sort classes

here is my code:

#include <iostream>
#include<string>
using namespace std;

class Employee
{
private:
    int idNum;
    string lastName;
    int hireDate;
    int verifyDate(int);
public:
    Employee();
    Employee(int,string,int);
    void displayData();
    void setLastName(string);
    void setIdNum(int);
    void setHireDate(int);
    void setGradePointAverage(double);
};

Employee::Employee()
{
    idNum=0;
    lastName="";
    hireDate=0;
}

Employee::Employee(int idNum, string lastName, int hireDate)
{
    this->idNum=idNum;
    this->lastName=lastName;
    this->hireDate=hireDate;
}

void Employee::displayData()
{
    cout<<"\nEmployee Data:";
    cout<<"\nID: "<<idNum;
    cout<<"\nLastName: "<<lastName;
    cout<<"\nHireDate: "<<hireDate;
}

void Employee::setLastName(string lastName)
{
    this->lastName=lastName;
}

void Employee::setIdNum(int idNum)
{
    this->idNum=idNum;
}

void Employee::setHireDate(int hireDate)
{
    this->hireDate=hireDate;
}

void Employee::setGradePointAverage(double grade)
{
    double new_grade;
    new_grade=grade;
}



template <class T>
void selectionSort (T data[], int n){
    T temp;
    for(int i=0, j, least; i < n-1; i++){
        for( j = i+1, least = i; j < n; j++ ){
            if ( data[j] < data[least]){
                least = j;
            }
        }
        temp = data[least];
        data[least] = data[i];
        data[i] = temp;
    }
}


int main()
{
    Employee e[3];

    e[0].setIdNum(337322);
    e[1].setIdNum(3539854);
    e[2].setIdNum(1224567);

    e[0].setLastName("Marlen");
    e[1].setLastName("Oleg");
    e[2].setLastName("Test");

    e[0].setHireDate(25061989);
    e[1].setHireDate(30001990);
    e[2].setHireDate(12122012);

    for (int i=0; i<3;i++)
    {
        e[i].displayData();
        cout<<"\n";
    }

    selectionSort(e,3);




    return 0;
}

when i call my selectionSort function the compiler gives me the following errors:

Error   1   error C2784: 'bool std::operator <(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'Employee'   c:\users\gulmira\documents\visual studio 2010\projects\csci203_lab1\csci203_lab1\task6.cpp  74
Error   2   error C2784: 'bool std::operator <(const _Elem *,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const _Elem *' from 'Employee' c:\users\gulmira\documents\visual studio 2010\projects\csci203_lab1\csci203_lab1\task6.cpp  74
Error   3   error C2784: 'bool std::operator <(const std::basic_string<_Elem,_Traits,_Alloc> &,const std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'Employee' c:\users\gulmira\documents\visual studio 2010\projects\csci203_lab1\csci203_lab1\task6.cpp  74

Please suggest an idea for how to solve this, Thanks in Advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T11:14:53+00:00Added an answer on May 29, 2026 at 11:14 am

    As the error points out, there is no operator< for Employee, but you are trying to use it in your sorting function.
    You need to choose an ordering criteria (e.g. numerically by employee id) and implement operator< accordingly.

    E.g.:

    bool Employee::operator<(const Employee& rhs) const { 
        return idNum < rhs.idNum; 
    }
    

    If you want to give the caller the choice of the ordering criteria, you can do it like std::sort() by allowing a functor or function pointer to be passed that will be used for the comparisons:

    template <class T, class Comp>
    void selectionSort (T data[], int n, Comp comp){
        // ...
        if (comp(data[j], data[least])) {
        // ...
    

    … which you could then e.g. use like this:

    bool orderEmployeesByLastName(const Employee& a, const Employee& b) {
        return std::lexicographical_compare(
                   a.getLastName().begin(), a.getLastName.end(), 
                   b.getLastName().begin(), b.getLastName.end());
    }
    
    // ... 
    selectionSort(e, 3, &orderEmployeesByLastName);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good evening. I am doing a basic exercise to insert data into an Access
Good evening all, I've been working on an MD5 tool in C# that takes
Good evening, I am working on a program where some application config info is
Good evening, I made a well working function with php, mysql and ajax. A
Good evening, I am working to get my head around unit testing and I'm
Good evening, I have a Dedicated Server in a data center and i want
Good evening, experts I want to solve recurrence equation using mathematica, x(n) = x(n
Good evening, I'm working on a project that has a list of seven options
Good evening everyone! I am working on learning some java and I have made
Good evening I've got a little problem with my DataGridView in a .NET Windows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.