Note that there are some explanatory texts on larger screens.

plurals
  1. POisAbstract template and visual studio
    primarykey
    data
    text
    <p>The following template will decide if T is abstract with g++.</p> <pre><code>/** isAbstract&lt;T&gt;::result is 1 if T is abstract, 0 if otherwise. */ template&lt;typename T&gt; class isAbstract { class No { }; class Yes { No no[3]; }; template&lt;class U&gt; static No test( U (*)[1] ); // not defined template&lt;class U&gt; static Yes test( ... ); // not defined public: enum { result = sizeof( isAbstract&lt;T&gt;::template test&lt;T&gt;( 0 ) ) == sizeof(Yes) }; }; </code></pre> <p>For example: struct myClass2 { virtual void f() {} }; struct myClass1 { virtual void f() = 0; };</p> <pre><code>bool twoAbstract = isAbstract&lt;myClass2&gt;::result; bool oneAbstract = isAbstract&lt;myClass1&gt;::result; </code></pre> <p>However, it fails in visual studio 9.0 with the error:</p> <pre><code>error C2784: 'AiLive::isAbstract&lt;T&gt;::No AiLive::isAbstract&lt;T&gt;::test(U (*)[1])' : could not deduce template argument for 'U (*)[1]' from 'myClass2' </code></pre> <p>Does anyone have an idea of what the problem is and how to fix this?</p> <p><a href="http://msdn.microsoft.com/en-us/library/bb982572.aspx" rel="nofollow noreferrer">MSDN</a> Reports that they now have an <code>is_abstract</code> class since VS2008 as part of TR1 (inside the header <code>type_traits</code>). However, it seems to be missing from my installation.</p> <p>PS. For reasons that are long and boring, I can't reimplement this via Boost.</p> <p><em>Update</em></p> <p>Also, tried replacing,</p> <pre><code>template&lt;class U&gt; static No test( U (*)[1] ); </code></pre> <p>with each of,</p> <pre><code>template&lt;class U&gt; static No test( U (*x)[1] ); template&lt;class U&gt; static No test( U (*)() ); template&lt;class U&gt; static No test( U (*x)() ); </code></pre> <p>and</p> <pre><code>template &lt;typename U&gt; struct U2 : public U { U2( U* ) {} }; // Match if I can make a U2 template &lt;typename U&gt; static No test( U2&lt;U&gt; x ); </code></pre> <p>and</p> <pre><code>// Match if I can make a U2 template &lt;typename U&gt; static No test( U2&lt;T&gt; x ); </code></pre> <p>No luck - all say that template argument cannot be deduced for U.</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