Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is this class abstract?
    primarykey
    data
    text
    <p>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:</p> <pre><code> 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 &lt;&lt; number;//add number to the stream return ss.str();//return a string with the contents of the stream } int compareTo(Term * term) { if(this-&gt;exponentX &gt; term-&gt;exponentX) { return 1; } else if(this-&gt;exponentX &lt; term-&gt;exponentX) { return -1; } else { if(this-&gt;exponentY &gt; term-&gt;exponentY) { return 1; } else if(this-&gt;exponentY &lt; term-&gt;exponentY) { return - 1; } else { return 0; } } } string toString() { stringstream s; int * current = &amp;this-&gt;coefficient; if(*current == 1 || *current == -1) { } else if(coefficient != 0) { s &lt;&lt; convertInt(coefficient); } else { return s.str(); } if(variable1 != "" &amp;&amp; this-&gt;exponentX != 0) { s &lt;&lt; variable1; s &lt;&lt; convertInt(exponentX); } if(variable2 != "" &amp;&amp; this-&gt;exponentY != 0) { s &lt;&lt; variable2; s &lt;&lt; convertInt(exponentY); } return s.str(); } }; </code></pre> <p>Also, here is implementation of LinkedList. There are some other methods in there, but they don't seem to be giving any issues.</p> <p>LinkedList.cpp:</p> <pre><code> class Polynomial : public LinkedList { public: Term head; Polynomial() { this-&gt;head = NULL; } ~Polynomial() { Term * current = head; while (current != NULL) { Term * next = current-&gt;next; delete current; current = next; } } </code></pre> <p>Thank you!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload