<?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 Konstruktor kann nicht aus abgeleiteter Klasse benutzt werden]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe folgenen Code</p>
<pre><code class="language-cpp">class Base
{
    protected:
    Base (int, int);
    public:
    Base (int);
};

class Derived : public Base
{
    public:
    Derived (int);
    void func (int, int);
};

Derived::Derived (int a) : Base (a)
{
}

void Derived::func (int a, int b)
{
    Base test(a,b);
}

int main (void)
{
    Derived test1(3);
    test1.func(3,4);
}
</code></pre>
<p>Eigentlich sollte man ja aus einer abgeleiteten Klasse auf protected Elemente/Funktionen der Basis-Klasse zugreifen können, oder?</p>
<p>Meine Frage, wieso geht das in dem Beispiel nicht?</p>
<p>Comeau-Fehler: &quot;ComeauTest.c&quot;, line 22: error: protected function &quot;Base::Base(int, int)&quot; is not<br />
accessible through a &quot;Base&quot; pointer or object<br />
Base test(a,b);</p>
<p>Schonmal vielen Dank</p>
<p>Felix</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/123348/protected-konstruktor-kann-nicht-aus-abgeleiteter-klasse-benutzt-werden</link><generator>RSS for Node</generator><lastBuildDate>Sun, 23 Aug 2026 12:19:27 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/123348.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 15 Oct 2005 17:44:35 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Protected Konstruktor kann nicht aus abgeleiteter Klasse benutzt werden on Sat, 15 Oct 2005 17:44:35 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich habe folgenen Code</p>
<pre><code class="language-cpp">class Base
{
    protected:
    Base (int, int);
    public:
    Base (int);
};

class Derived : public Base
{
    public:
    Derived (int);
    void func (int, int);
};

Derived::Derived (int a) : Base (a)
{
}

void Derived::func (int a, int b)
{
    Base test(a,b);
}

int main (void)
{
    Derived test1(3);
    test1.func(3,4);
}
</code></pre>
<p>Eigentlich sollte man ja aus einer abgeleiteten Klasse auf protected Elemente/Funktionen der Basis-Klasse zugreifen können, oder?</p>
<p>Meine Frage, wieso geht das in dem Beispiel nicht?</p>
<p>Comeau-Fehler: &quot;ComeauTest.c&quot;, line 22: error: protected function &quot;Base::Base(int, int)&quot; is not<br />
accessible through a &quot;Base&quot; pointer or object<br />
Base test(a,b);</p>
<p>Schonmal vielen Dank</p>
<p>Felix</p>
]]></description><link>https://www.c-plusplus.net/forum/post/892992</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/892992</guid><dc:creator><![CDATA[Phoemuex]]></dc:creator><pubDate>Sat, 15 Oct 2005 17:44:35 GMT</pubDate></item><item><title><![CDATA[Reply to Protected Konstruktor kann nicht aus abgeleiteter Klasse benutzt werden on Sat, 15 Oct 2005 17:57:16 GMT]]></title><description><![CDATA[<p>ich bin selber noch nicht so fit in c++, aber soweit ich das überblicke ist eine protectet-funktion nur auf <em>this</em> anwendbar. du willst den konstruktor aber auf ein neu erzeugtes objekt <em>test</em> anwenden. den protected-konstruktor kannst du also nur in der initialisierungsliste des Derived-konstruktors aufrufen.</p>
<p>korrigiert mich, wenn ich falsch liege.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/893000</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/893000</guid><dc:creator><![CDATA[Konfusius]]></dc:creator><pubDate>Sat, 15 Oct 2005 17:57:16 GMT</pubDate></item><item><title><![CDATA[Reply to Protected Konstruktor kann nicht aus abgeleiteter Klasse benutzt werden on Sat, 15 Oct 2005 18:00:22 GMT]]></title><description><![CDATA[<p>protected bedeutet, dass abgeleitete Klassen in Ihren Funktionen diese Funktionen aufrufen dürfen (für das eigenen Objekt), Du kannst aber nicht Dir ein Objekt erzeugen und dann dessen protected Methoden aufrufen (egal ob in einer abgeleiteten Klasse oder sonst wo ausserhalb der eigentlichen Klasse).<br />
Da hilft entweder ein friend oder den Konstruktor public machen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/893003</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/893003</guid><dc:creator><![CDATA[niemand]]></dc:creator><pubDate>Sat, 15 Oct 2005 18:00:22 GMT</pubDate></item><item><title><![CDATA[Reply to Protected Konstruktor kann nicht aus abgeleiteter Klasse benutzt werden on Sat, 15 Oct 2005 18:03:02 GMT]]></title><description><![CDATA[<p>Zur Vervollstädigung:</p>
<blockquote>
<p>11.5 Protected member access [class.protected]<br />
1 When a friend or a member function of a derived class references a protected nonstatic member function or<br />
protected nonstatic data member of a base class, an access check applies in addition to those described earlier<br />
in clause 11.102) Except when forming a pointer to member (5.3.1), the access <strong>must be through a<br />
pointer to, reference to, or object of the derived class itself</strong> (or any class derived from that class) (5.2.5). If<br />
the access is to form a pointer to member, the nested-name-specifier shall name the derived class (or any<br />
class derived from that class).</p>
</blockquote>
<p>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/893005</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/893005</guid><dc:creator><![CDATA[FireFlow]]></dc:creator><pubDate>Sat, 15 Oct 2005 18:03:02 GMT</pubDate></item></channel></rss>