Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When you are overriding virtual methods, you have to match the function signatures <em>precisely</em>. The return type may vary in accordance with covariance rules, but the parameter types must be exactly the same.</p> <p>In the base class <code>Data</code> function <code>compareTo</code> is declared as</p> <pre><code>virtual int compareTo(Data * other) const </code></pre> <p>In the derived class <code>Term</code> it is declared as</p> <pre><code>int compareTo(Term * term) </code></pre> <p>Firstly, the parameter type is different. Secondly, the <code>const</code> is missing.</p> <p>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 <code>Term</code> is still abstract.</p> <p>In <code>Term</code> you have to declare your function precisely as</p> <pre><code>int compareTo(Data * other) const </code></pre> <p>I assume that you expect to use <code>compareTo</code> in <code>Term</code> only for <code>Term</code>-to-<code>Term</code> comparisons. But in this design you'll have to either receive <code>Data</code> as an argument and then cast it to <code>Term</code>, or use the double-dispatch technique.</p> <p>P.S. On top of that you declare a <code>Term</code> object as a member <code>head</code> of your <code>Polynomial</code> class and then later use it as if it is a <em>pointer</em> </p> <pre><code>Term * current = head; </code></pre> <p>This makes no sense at all. If you want your <code>head</code> 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.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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