Note that there are some explanatory texts on larger screens.

plurals
  1. POType not found when derived from template base class
    primarykey
    data
    text
    <p>I'm having difficulty understanding why there is a difference in the following two pieces of code, what exactly is the compiler doing.</p> <p>I have the following bit of trivial code, that compiles without any problems as expected:</p> <pre><code>class base { public: typedef int booboo; }; class derived : public base { public: int boo() { booboo bb = 1; return bb; } }; int main() { derived d; d.boo(); return 0; } </code></pre> <p>I take the code from above and add some template parameters, and begin to get errors relating the type booboo not being valid:</p> <pre><code>template &lt;typename T&gt; class base { public: typedef T booboo; }; template &lt;typename T&gt; class derived : public base&lt;T&gt; { public: //typedef typename base&lt;T&gt;::booboo booboo; &lt;-- fixes the problem booboo boo() { booboo bb = T(1); return bb; } }; int main() { derived&lt;int&gt; d; d.boo(); return 0; } </code></pre> <p>Error:</p> <pre><code>prog.cpp:13:4: error: ‘booboo’ does not name a type prog.cpp:13:4: note: (perhaps ‘typename base&lt;T&gt;::booboo’ was intended) prog.cpp: In function ‘int main()’: prog.cpp:23:6: error: ‘class derived&lt;int&gt;’ has no member named ‘boo’ </code></pre> <p><a href="http://ideone.com/jGKYIC" rel="nofollow">http://ideone.com/jGKYIC</a></p> <p>.</p> <p>I would like to understand in details, how a typical c++ compiler goes about compiling the template version of the code, how it differs from compiling the original example, is this an issue to do with multiple passes of the code, and type dependent look-ups?</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