Note that there are some explanatory texts on larger screens.

plurals
  1. POPartially specialized explicit template specialization
    primarykey
    data
    text
    <p>I'm trying to write a fixed point arithmetic class where point position and underlying type are templates</p> <pre><code>template &lt;int P, typename T&gt; class basic_fixedpoint{ //stuff }; </code></pre> <p>I also want to expose a single templated implicit constructor that is then specialized for various types</p> <pre><code>//inside basic_fixedpoint template &lt;typename U&gt; basic_fixedpoint(const U&amp; arg); </code></pre> <p>Elsewhere I will implement specializations for int, float, double, etc. However, I also want to provide a generic specialization for any type of basic_fixedpoint with different P and T. How can I do this as a templated template specialization?</p> <pre><code>template &lt;int P, typename T&gt; //for the class whose constructor i specialize template &lt;int OP, typename OT&gt; //for the parameters of the argument basic_fixedpoint&lt;P, T&gt;::basic_fixedpoint&lt;basic_fixedpoint&lt;OP, OT&gt; &gt;(const basic_fixedpoint&lt;OP, OT&gt;&amp; arg) : /*init things here*/ {} // this fails </code></pre> <p>I'm trying to avoid overloading the constructor so as to present a single interface in the header, telling the user "This class will cleanly construct itself from whatever type you give it, or it will fail to compile and give you an incomprehensible paragraph long error message"</p> <p>As a sub question: This class also implements the basic operator int(), operator float(), operator double() conversions, and also overloaded arithmetic operators and math functions are provided. Naturally, whenever I try to invoke anything with this class, the call is ambiguous because every possibility is available. </p> <p>How can I keep this class fully flexible, but still allow pain-free unambiguous overloaded function calls that behave properly (rather than always converting my class to a double and back)?</p>
    singulars
    1. This table or related slice is empty.
    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