Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to make the <code>enable_if</code> dependent on a template parameter. As it is now, it is only dependent on the outer template parameter within the template definition. But if you instantiate a class from the outer template, then your assignment operator template that is instantiated into that class is not dependent on a template parameter anymore because <code>T</code> will have been substituted already. </p> <p>Just introduce a dummy parameter equal to <code>T</code></p> <pre><code>template&lt;typename T1 = T, typename = typename std::enable_if&lt; ( !std::is_same&lt; X&lt;T1&gt;, typename StrangerTypeRules&lt;T1&gt;::type &gt;::value ), X&lt;T1&gt; &gt;::type &gt; X&lt;T1&gt; &amp; operator=( const typename StrangerTypeRules &lt;T1&gt;::type&amp; rhs ) { return *this; } </code></pre> <p>Using <code>T1</code> in just one of theplaces within the <code>enable_if&lt;...&gt;</code> template arguments would suffice already, because that already makes the <code>enable_if</code> dependent. </p> <p>However it is <em>not</em> the call to your <code>operator=</code> that was previously illformed but the <em>declaration</em> of it, which conflicts with the copy-assignment operator, so the <code>enable_if</code> has little utility here. Just replace your code by</p> <pre><code>template&lt;typename T1 = T&gt; X&lt;T1&gt; &amp; operator=( const typename StrangerTypeRules &lt;T1&gt;::type&amp; rhs ) { return *this; } </code></pre> <p>Since this <code>operator=</code> is a template, it will not conflict with the non-template overload. And also because it is a template, when you call it the compiler will prefer the non-template if <code>T</code> is <code>X&lt;T&gt;</code>.</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