Note that there are some explanatory texts on larger screens.

plurals
  1. POInheritance issues with template classes
    primarykey
    data
    text
    <p>I'm having issues with a very strange error in some code I wrote. The basic idea behind the code can be trivialised in the following example:</p> <p><pre><code> template &lt;class f, class g> class Ptr;</p> <p>template &lt;class a, class b, class c = Ptr&lt;a,b> > class Base { public: Base(){}; };</p> <p>template &lt;class d, class e> class Derived : public Base &lt;d,e> { public: Derived(){}; };</p> <p>template &lt;class f, class g> class Ptr { public: Ptr(){}; Ptr(Base&lt;f,g,Ptr&lt;f,g> >* a){}; };</p> <p>typedef Derived&lt;double,double> DDerived;</p> <p>int main() { Base&lt;int,int> b = Base&lt;int,int>(); Derived&lt;double,double> d = Derived&lt;double,double>(); DDerived dd = DDerived(); Ptr&lt;double,double> p(&amp;dd); return 1; } </pre></code></p> <p>The basic idea is that pointers are replaced by the Ptr class (This will eventually be used in an MPI setting so standard pointers are effectively useless). The pointers are designed to 'point' at the base class, and so can point at any inherited class (as demonstrated in the example).</p> <p>Can anyone think of any reason this might <em>not</em> work in a non-trivial case (But a case where the object architecture remains identical).</p> <p>The error that is occurring in the main case is as follows:</p> <p><pre><code> void function() { vector nVector(1); // cut down for simplicity nVector[0].SetId(1); // To ensure the node is instantiated correctly Ptr temp(&amp;nVector[1]); }; </pre></code></p> <p>This code produces the (slightly extended version of the) error when compiled with <code>MPICXX:</code><br /> no matching function for call to <code>Ptr&amp;lt;double, double&gt;::Ptr(Derived&amp;lt;double, double&gt;*)</code><br /> candidates are . . . (Some removed for simplicity's sake) <br /> <code>Ptr&amp;lt;f, g&gt;::Ptr(Base&amp;lt;f, g, Ptr&amp;lt;f, g&gt; &gt;*) [with f = double, g = double]</code></p> <p>Cheers, Ed</p> <p>EDITED (Detailing the error a little better, added info on the compiler)</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.
 

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