<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Can compile in MSVS, but cannot compile in GCC]]></title><description><![CDATA[<p>Hello!</p>
<p>Here is my code:</p>
<pre><code>template&lt;class T&gt; class Test1;
template&lt;class T&gt; class Test2;

template&lt;class T&gt; class Test1
{
public:
  typedef Test2&lt;T&gt; *myPointer;
};

template&lt;class T&gt; class Test2: Test1&lt;T&gt;
{
  myPointer intPointer;
};

int main()
{
  Test2&lt;int&gt; x;
  return 0;
}
</code></pre>
<p>Error is «myPointer does not name a type».<br />
What I am doing wrong?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/256174/can-compile-in-msvs-but-cannot-compile-in-gcc</link><generator>RSS for Node</generator><lastBuildDate>Tue, 08 Sep 2026 16:29:56 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/256174.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 09 Dec 2009 09:47:12 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Can compile in MSVS, but cannot compile in GCC on Wed, 09 Dec 2009 09:47:12 GMT]]></title><description><![CDATA[<p>Hello!</p>
<p>Here is my code:</p>
<pre><code>template&lt;class T&gt; class Test1;
template&lt;class T&gt; class Test2;

template&lt;class T&gt; class Test1
{
public:
  typedef Test2&lt;T&gt; *myPointer;
};

template&lt;class T&gt; class Test2: Test1&lt;T&gt;
{
  myPointer intPointer;
};

int main()
{
  Test2&lt;int&gt; x;
  return 0;
}
</code></pre>
<p>Error is «myPointer does not name a type».<br />
What I am doing wrong?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1819962</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1819962</guid><dc:creator><![CDATA[SAn]]></dc:creator><pubDate>Wed, 09 Dec 2009 09:47:12 GMT</pubDate></item><item><title><![CDATA[Reply to Can compile in MSVS, but cannot compile in GCC on Wed, 09 Dec 2009 09:56:09 GMT]]></title><description><![CDATA[<p>Yes, your Code is wrong. But GCC tells you what to do</p>
<pre><code>foo.c++:12: error: ‘myPointer’ does not name a type
foo.c++:12: note: (perhaps ‘typename Test1&lt;T&gt;::myPointer’ was intended)
</code></pre>
<p>(see the note comment)</p>
<pre><code class="language-cpp">template&lt;class T&gt; class Test1;
template&lt;class T&gt; class Test2;

template&lt;class T&gt; class Test1
{
public:
  typedef Test2&lt;T&gt; *myPointer;
};

template&lt;class T&gt; class Test2: Test1&lt;T&gt;
{
  typename Test1&lt;T&gt;::myPointer intPointer;
};

int main()
{
  Test2&lt;int&gt; x;
  return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1819967</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1819967</guid><dc:creator><![CDATA[rüdiger]]></dc:creator><pubDate>Wed, 09 Dec 2009 09:56:09 GMT</pubDate></item><item><title><![CDATA[Reply to Can compile in MSVS, but cannot compile in GCC on Wed, 09 Dec 2009 10:06:33 GMT]]></title><description><![CDATA[<p>the problem is that myPointer is a dependent name that needs to be qualified and marked as a typename, like ruediger showed. Imagine the following specialization of Test1:</p>
<pre><code class="language-cpp">template&lt;class T&gt; class Test1
{
public:
  typedef Test2&lt;T&gt; *myPointer; //ok, so normally myPointer is a type
};

template&lt;&gt; class Test1&lt;int&gt;
{
public:
  int* myPointer; //ouch, here myPointer is a member variable!
};

template&lt;class T&gt; class Test2: Test1&lt;T&gt;
{
  myPointer intPointer; //so what is myPointer here?
};
</code></pre>
<p>because the compiler cannot know what the &quot;member&quot; myPointer of Test1&lt;T&gt; really is, it assumes it to be a member variable or function. Therefore the need for the typename keyword. In addition,the compiler cannot know where the name myPointer should come from. Test1&lt;T&gt; is still a template that is not instantiated during the first pass through the code, the compiler simply doesnt know which names are inherited from there and considers myPointer an error. Therefore you need to tell him explicitly where that name comes from by qualifying it.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1819974</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1819974</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Wed, 09 Dec 2009 10:06:33 GMT</pubDate></item><item><title><![CDATA[Reply to Can compile in MSVS, but cannot compile in GCC on Wed, 09 Dec 2009 10:16:25 GMT]]></title><description><![CDATA[<p>I know. I have read the note.</p>
<p>The problem is that I have big project where similar errors are everywhere, even if the member (or type) is declared in the same class (not in its ancestor).</p>
<p>I am asking for the explanation of this effect.</p>
<p>Update: thank you, <strong>pumuckl</strong>.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1819976</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1819976</guid><dc:creator><![CDATA[SAn]]></dc:creator><pubDate>Wed, 09 Dec 2009 10:16:25 GMT</pubDate></item><item><title><![CDATA[Reply to Can compile in MSVS, but cannot compile in GCC on Wed, 09 Dec 2009 10:26:30 GMT]]></title><description><![CDATA[<p>Is there any way to say GCC compiler to instantiate templates (to analyse their code) only in cases of their use (as in MSVS)? I think this way the compiler will know values of template parameters, and such problems will not occur.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1819983</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1819983</guid><dc:creator><![CDATA[SAn]]></dc:creator><pubDate>Wed, 09 Dec 2009 10:26:30 GMT</pubDate></item><item><title><![CDATA[Reply to Can compile in MSVS, but cannot compile in GCC on Wed, 09 Dec 2009 11:09:25 GMT]]></title><description><![CDATA[<p>SAn schrieb:</p>
<blockquote>
<p>Is there any way to say GCC compiler to instantiate templates (to analyse their code) only in cases of their use (as in MSVS)? I think this way the compiler will know values of template parameters, and such problems will not occur.</p>
</blockquote>
<p>This ist no error in gcc, and IIRC it's not about the instantiation. The Compiler passes two times through the template code, where the first time is mainly about syntax checking and some name lookup and here the error occurs. The standard says it is an error, so gcc complains about it (and is right about that, imho). AFAIK, MSVC is a bit lazy in that first phase and thus does not see the error, because in the second phase the base class template has already been instantiated and therefore the name is already known and everything is fine.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1820005</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1820005</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Wed, 09 Dec 2009 11:09:25 GMT</pubDate></item></channel></rss>