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 8226755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:53:10+00:00 2026-06-07T15:53:10+00:00

I’m trying to create an implementation of a LinkedList that represents polynomials. The Linked

  • 0

I’m trying to create an implementation of a LinkedList that represents polynomials. The Linked list is going to be a list of “Term”s. A term is an implementation of Data (which is an abstract class with methods: compareTo() and toString()). The Polynomial class has a variable called head which I am trying to initialize as a Term. My compiler is saying that I “cannot declare member of abstract type: Term”, but I did not think Term was abstract because it is an implementation of Data (the abstract class). If you guys could take a look at this and let me know of any huge red flags I’m missing, I would greatly appreciate it.
Collection.h:

  class Data {
  public:
  virtual ~Data() {}

virtual int compareTo(Data * other) const = 0;

virtual string toString() const = 0;
};

class Term : public Data { 
public:
int coefficient;
string variable1;
int exponentX;
string variable2;
int exponentY;
Term * next;

Term(int coeff, string var1, int exp1, string var2, int exp2, Term * next) : 
    coefficient(coeff), 
    variable1(var1),
    exponentX(exp1),
    variable2(var2),
    exponentY(exp2),
    next(next) {};

string convertInt(int number) {
    stringstream ss;//create a stringstream
    ss << number;//add number to the stream
    return ss.str();//return a string with the contents of the stream
}

int compareTo(Term * term) {
    if(this->exponentX > term->exponentX) {
    return 1;
    }
    else if(this->exponentX < term->exponentX) {
    return -1;
    }
    else {
        if(this->exponentY > term->exponentY) {
        return 1;
        }
        else if(this->exponentY < term->exponentY) {
        return - 1;
        }
        else {
        return 0;
        }
    }
}
string toString() {
    stringstream s;
    int * current = &this->coefficient;
    if(*current == 1 || *current == -1) {
    }
    else if(coefficient != 0) {
    s << convertInt(coefficient);
    }
    else { return s.str(); }
    if(variable1 != "" && this->exponentX != 0) {
    s << variable1;
    s << convertInt(exponentX);
    }
    if(variable2 != "" && this->exponentY != 0) {
    s << variable2;
    s << convertInt(exponentY);
    }
return s.str();
}   
};

Also, here is implementation of LinkedList. There are some other methods in there, but they don’t seem to be giving any issues.

LinkedList.cpp:

 class Polynomial : public LinkedList { 
public:
Term head;

Polynomial() {
this->head = NULL;
}

~Polynomial() {
Term * current = head;
    while (current != NULL) {
        Term * next = current->next;
        delete current;
        current = next;
    }
}

Thank you!

  • 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-07T15:53:12+00:00Added an answer on June 7, 2026 at 3:53 pm

    When you are overriding virtual methods, you have to match the function signatures precisely. The return type may vary in accordance with covariance rules, but the parameter types must be exactly the same.

    In the base class Data function compareTo is declared as

    virtual int compareTo(Data * other) const
    

    In the derived class Term it is declared as

    int compareTo(Term * term)
    

    Firstly, the parameter type is different. Secondly, the const is missing.

    This means that you wrote a completely unrelated function in the derived class. It does not override the base class’s pure virtual function. Since the base pure virtual function remain non-overriden, class Term is still abstract.

    In Term you have to declare your function precisely as

    int compareTo(Data * other) const
    

    I assume that you expect to use compareTo in Term only for Term-to-Term comparisons. But in this design you’ll have to either receive Data as an argument and then cast it to Term, or use the double-dispatch technique.

    P.S. On top of that you declare a Term object as a member head of your Polynomial class and then later use it as if it is a pointer

    Term * current = head;
    

    This makes no sense at all. If you want your head to be a pointer, declare it as a pointer. If you want it to be an object, then stop using it as a pointer. Either this or that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:

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.