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

  • Home
  • SEARCH
  • 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 8009825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:33:33+00:00 2026-06-04T18:33:33+00:00

I want to created a generic sorted linked list. Thus I have an abstract

  • 0

I want to created a generic sorted linked list. Thus I have an abstract class Data, with a pure operator< (in order to easily sort the list. I believe it is called a comperator.) Now I have a class Job which derives from Data and implements the operator. The problem rises when I try to create a list of jobs and find out that job is also abstract. It happens because the operator I wrote in Job doesn’t have the exact same signature as in Data –
in data:

virtual bool operator<(const Data& other) const =0;

and in job:

virtual bool operator<(const Job& other) const;

I had to receive job in job’s operator since I can’t compare job to a generic data. But now the new operator just hides the old one instead of overriding it (or implementing it because it is pure).
How can I solve the problem without using downcasting?
Thanks!
Edit: and without templates.

  • 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-06-04T18:33:36+00:00Added an answer on June 4, 2026 at 6:33 pm

    Without using downcasting… seems like a job for templates.

    You can enforce the implementation of the comparison function using the operator directly, and not necessarily declaring it as pure virtual. And it’s also generic.

    Same result, different approach. More flexibility, since you don’t have to derive from something (which can become a pain if you start using multiple inheritance).

    template<typename T>
    class SortedLinkedList
    {
        T* head;
        void insertItem(const T& item)
        {
           T* currentNode = head;
           //iterate
           {
              if ( *currentNode < item ) // force implementation of operator <
              { /* whatever */ }
           }
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a customized CursorAdapter and want to select a list item, in order
I have a class User. I have created a generic CSV exporter that works
I have created a Area class using Linq-to-SQL. Now I want to create a
So I have created a List of a Custom Class called FinalPixel , and
I have a DataTable (or Generic List) that I want to bind to 2
I created the following class in order to have an easy way to display
I have a data object that has many different List properties. I want to
i have one problem with handling list,i have three class named as UserInf,userData,userProcess,i created
I have a generic List of Policy objects. The list contains the following data
I have created a data table using disconnected class, also created the data set,xml

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.