Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When we call these two lines:</p> <pre><code>TemplateClass&lt;TemplateClass&lt;EmptyClass&gt; &gt; c; TemplateClass&lt;std::string&gt;::static_method(c); </code></pre> <p>then the type argument U is the type of the object c:</p> <pre><code>TemplateClass&lt;TemplateClass&lt;EmptyClass&gt; &gt; </code></pre> <p>Let's leave <code>static_method</code>, and do an experiment:</p> <pre><code>#include &lt;iostream&gt; #include &lt;typeinfo.h&gt; using namespace std; template&lt;typename T&gt; class TemplateClass : public T { public: void method(int i) { cout &lt;&lt; i &lt;&lt; ": "; cout &lt;&lt; typeid(*this).name() &lt;&lt; endl; } }; class EmptyClass { }; void main() { TemplateClass&lt;TemplateClass&lt;EmptyClass&gt; &gt; u; u.method(1); u.TemplateClass::method(2); u.TemplateClass&lt;EmptyClass&gt;::method(3); u.TemplateClass&lt;TemplateClass&lt;EmptyClass&gt; &gt;::method(4); } </code></pre> <p>The output is:</p> <pre><code>1: class TemplateClass&lt;class TemplateClass&lt;class EmptyClass&gt; &gt; 2: class TemplateClass&lt;class TemplateClass&lt;class EmptyClass&gt; &gt; 3: class TemplateClass&lt;class EmptyClass&gt; 4: class TemplateClass&lt;class TemplateClass&lt;class EmptyClass&gt; &gt; </code></pre> <p>In all four cases (and inside <code>static_method</code>) we call <code>TemplateClass&lt;T&gt;::method</code>, and the type name given between <code>u.</code> and <code>::</code> will give the actual type T: </p> <ul> <li>Case #1 is the default, here T is given by the declaration of u. </li> <li>Case #4 is also trivial.</li> <li>Case #2 looks as if the compiler should have guessed the type argument of TemplateClass, which is trivially the one given in the declaration of u.</li> <li>Case #3 is very interesting. I guess function type casting happened here, from <code>TemplateClass&lt;TemplateClass&lt;EmptyClass&gt; &gt;::method</code> to <code>TemplateClass&lt;EmptyClass&gt;::method</code>.</li> </ul> <p>I don't know whether this behavior is part of the C++ standard. </p> <p><strong>EDIT:</strong></p> <p>Actually case #3 is not casting, these are <strong>qualified names</strong>. So in conclusion, Clang is not aware of this qualification syntax, while both GCC and Visual C++ 2010 are.</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. 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