<?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[Protected member von SuperSuperClass nicht sichtbar für templated Klasse ?]]></title><description><![CDATA[<p>Hallo,<br />
ich habe eine kompliziertere Vererbungshierarchie gepaart mit Templates und bin beim compilieren mit g++ erst darauf gestoßen, daß eine Member Variable nicht sichtbar ist.</p>
<p>Das &quot;Besondere&quot; daran ist, daß ich eine Verbungshierarchie von 3 Klassen habe, wobei die letzten zwei templated sind.</p>
<p>Hier das Beispiel:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

using namespace std;

class Grandpa {
public:
    Grandpa() { mGrandpas = 20; };
    virtual ~Grandpa() { };
protected:
    int mGrandpas;
};

template &lt; class T &gt;
class Daddy : public Grandpa  {
public:
    Daddy() {};
    virtual ~Daddy() {};
};

template &lt; class T &gt;
class Child : public Daddy &lt; T &gt; {
public:

    Child( ) { };

    virtual int A()
    {
        cout &lt;&lt; mGrandpas &lt;&lt; endl; // #1 does not compile !!! -&gt; not declared in this scope
        cout &lt;&lt; Grandpa::mGrandpas &lt;&lt; endl; // #2 does not compile !!! object missing in reference to
        cout &lt;&lt; Daddy&lt;T&gt;::mGrandpas &lt;&lt; endl; // #3 works!
        return 20;
    }
};

int main() {
    Child&lt;int&gt; lC();

    cout &lt;&lt; lC.A() &lt;&lt; endl;
}
</code></pre>
<p>Warum gibt es diese Probleme , d.h. warum gibt es die Fehler in #1 und #2 aber nicth nicht mit #3 ?<br />
Ich habe auch beobachtet, daß wenn ich die Abstraktionsschicht mit Daddy&lt;T&gt; nicht templated mache, der Fehler nicht auftritt.</p>
<p>Carstig.</p>
<p>p.s. der Fehler tritt mit g++ (version 3.4.6 unter RedHat Linux als auch mit g++ 3.4.4 unter Win/Cygwin auf) aber nicht mit xlC unter AIX auf.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/210865/protected-member-von-supersuperclass-nicht-sichtbar-für-templated-klasse</link><generator>RSS for Node</generator><lastBuildDate>Tue, 13 Oct 2026 17:31:06 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/210865.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 16 Apr 2008 09:40:43 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Protected member von SuperSuperClass nicht sichtbar für templated Klasse ? on Wed, 16 Apr 2008 09:40:43 GMT]]></title><description><![CDATA[<p>Hallo,<br />
ich habe eine kompliziertere Vererbungshierarchie gepaart mit Templates und bin beim compilieren mit g++ erst darauf gestoßen, daß eine Member Variable nicht sichtbar ist.</p>
<p>Das &quot;Besondere&quot; daran ist, daß ich eine Verbungshierarchie von 3 Klassen habe, wobei die letzten zwei templated sind.</p>
<p>Hier das Beispiel:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

using namespace std;

class Grandpa {
public:
    Grandpa() { mGrandpas = 20; };
    virtual ~Grandpa() { };
protected:
    int mGrandpas;
};

template &lt; class T &gt;
class Daddy : public Grandpa  {
public:
    Daddy() {};
    virtual ~Daddy() {};
};

template &lt; class T &gt;
class Child : public Daddy &lt; T &gt; {
public:

    Child( ) { };

    virtual int A()
    {
        cout &lt;&lt; mGrandpas &lt;&lt; endl; // #1 does not compile !!! -&gt; not declared in this scope
        cout &lt;&lt; Grandpa::mGrandpas &lt;&lt; endl; // #2 does not compile !!! object missing in reference to
        cout &lt;&lt; Daddy&lt;T&gt;::mGrandpas &lt;&lt; endl; // #3 works!
        return 20;
    }
};

int main() {
    Child&lt;int&gt; lC();

    cout &lt;&lt; lC.A() &lt;&lt; endl;
}
</code></pre>
<p>Warum gibt es diese Probleme , d.h. warum gibt es die Fehler in #1 und #2 aber nicth nicht mit #3 ?<br />
Ich habe auch beobachtet, daß wenn ich die Abstraktionsschicht mit Daddy&lt;T&gt; nicht templated mache, der Fehler nicht auftritt.</p>
<p>Carstig.</p>
<p>p.s. der Fehler tritt mit g++ (version 3.4.6 unter RedHat Linux als auch mit g++ 3.4.4 unter Win/Cygwin auf) aber nicht mit xlC unter AIX auf.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1492828</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1492828</guid><dc:creator><![CDATA[Carstig]]></dc:creator><pubDate>Wed, 16 Apr 2008 09:40:43 GMT</pubDate></item><item><title><![CDATA[Reply to Protected member von SuperSuperClass nicht sichtbar für templated Klasse ? on Wed, 16 Apr 2008 09:45:29 GMT]]></title><description><![CDATA[<p>Die unvollständige Template-Basis wird nicht in die Namenssuche mit einbezogen. Schließlich könnte, wenn eine konkrete Instanz von Child erzeugt wird, T so gewählt sein dass Daddy&lt;T&gt; eine Spezialisierung ist, die garkein mGrandpas enthält. Das ist so auch standardkonform.</p>
<p>Um nicht immer den Basisklassennamen angeben zu müssen, kannst Du this-&gt;mGrandpas ansprechen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1492830</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1492830</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Wed, 16 Apr 2008 09:45:29 GMT</pubDate></item></channel></rss>