Note that there are some explanatory texts on larger screens.

plurals
  1. PONon-scalar type Sub-class error
    text
    copied!<p>I must be living in a bizarro version of C++. In a section of my code I have:</p> <pre><code>TemplateIterator&lt;sf::Sound&gt; Temp; TemplateIteratorNonConst&lt;sf::Sound&gt; Temp2 = Temp; </code></pre> <p>Ignore the 'constness' naming conventions as TemplateIteratorNonConst is not presently any different from TemplateIterator. I get the error:</p> <pre><code>'TL::TemplateIterator&lt;sf::Sound&gt;' to non-scalar type 'TL::TemplateIteratorNonConst&lt;sf::Sound&gt;' requested </code></pre> <p>Which implies that C++ is having conversion issues. The mind-boggling fact is, TemplateIteratorNonConst is an empty sub-derivative, <em>an exact duplicate of TemplateIterator[1]</em>:</p> <pre><code>//Empty to demonstrate the absurdity of the error template&lt;typename TemplateItem&gt; class TemplateIteratorNonConst : public TemplateIterator&lt;TemplateItem&gt; { private: protected: public: }; </code></pre> <p>Even if I define the assignment operator (no matter which kind - TemplateIterator to NonConsts, vice versa, same for same etc), it makes no difference, it spits out the same error. It wouldn't be such a confusing error if it wasn't for the fact that:</p> <pre><code>TemplateIterator&lt;sf::Sound&gt; Temp; TemplateList&lt;sf::Sound&gt; Temp2 = Temp; //A sub-class of TemplateIterator </code></pre> <p>Produces absolutely no errors. Why is it, TemplateList, a sub-class of TemplateIterator, gets no 'non-scalar type' warnings in the exact same scenario, but TemplateIteratorNonConst, also a sub-class (and exact dupe) of TemplateIterator, does?</p> <p>I can't give a full code example due to length of both TemplateIterator and TemplateList on this page, and I've been unable to replicate the error with simple classes (exact duplicate sub-classes give no errors when performing assignment either way).</p> <p>Why is this error occuring, and <strong>without static type-casting</strong> (given TemplateList requires no type-casting to work and TemplateIteratorNonConst is a self-explanatory duplicate of TemplateIterator so it should not be necessary) how do I fix the problem?</p> <p>(I feel static type-casting is covering up a more major problem on the underneath so I'd much rather address it).</p> <p>[1]Okay, maybe not an 'exact' duplicate (it is a subclass of TemplatorIterator) for pedants but you know what I mean.</p>
 

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