<?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[B has not been declared]]></title><description><![CDATA[<p>Hallo,</p>
<p>folgendes Minimalbeispiel welches mein Problem reflektiert. Ich gebe alle Dateien an und verstehe nicht warum der compiler mit der Meldung &quot;B has not been declared&quot; schreibt obwohl ich die Klasse B verfügbar mache. Wichtig: Impl.h ist keine Klasse sondern bietet nur die deklaration/definition von bar() an:</p>
<p>main.cpp</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &quot;A.h&quot;

int main(int argc, int** argv)
{
    int b = 8;

    A&lt;double&gt; a = A&lt;double&gt;(b);

}
</code></pre>
<p>A.h</p>
<pre><code class="language-cpp">#include &quot;Impl.h&quot;

#ifdef INCLUDE_A
#define INCLUDE_A

template &lt;class T&gt; class A
{
    public:
     A&lt;T&gt;(int b)
     {
        bar&lt;T&gt;(b);
     };
     ~A&lt;T&gt;() { };

};
#endif
</code></pre>
<p>Impl.h</p>
<pre><code class="language-cpp">#include &quot;B.h&quot;

template&lt;class T&gt; inline void
bar(int b, B b)
{
//    std::cout &lt;&lt; b &lt;&lt; std::endl;
}
</code></pre>
<p>B.h</p>
<pre><code class="language-cpp">#ifdef INCLUDE_B
#define INCLUDE_B

template &lt;class T&gt; class B
{
    public:
        B() { };
        ~B() { };

};

#endif
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/240320/b-has-not-been-declared</link><generator>RSS for Node</generator><lastBuildDate>Tue, 22 Sep 2026 01:52:42 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/240320.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 05 May 2009 10:47:29 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to B has not been declared on Tue, 05 May 2009 10:47:29 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>folgendes Minimalbeispiel welches mein Problem reflektiert. Ich gebe alle Dateien an und verstehe nicht warum der compiler mit der Meldung &quot;B has not been declared&quot; schreibt obwohl ich die Klasse B verfügbar mache. Wichtig: Impl.h ist keine Klasse sondern bietet nur die deklaration/definition von bar() an:</p>
<p>main.cpp</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &quot;A.h&quot;

int main(int argc, int** argv)
{
    int b = 8;

    A&lt;double&gt; a = A&lt;double&gt;(b);

}
</code></pre>
<p>A.h</p>
<pre><code class="language-cpp">#include &quot;Impl.h&quot;

#ifdef INCLUDE_A
#define INCLUDE_A

template &lt;class T&gt; class A
{
    public:
     A&lt;T&gt;(int b)
     {
        bar&lt;T&gt;(b);
     };
     ~A&lt;T&gt;() { };

};
#endif
</code></pre>
<p>Impl.h</p>
<pre><code class="language-cpp">#include &quot;B.h&quot;

template&lt;class T&gt; inline void
bar(int b, B b)
{
//    std::cout &lt;&lt; b &lt;&lt; std::endl;
}
</code></pre>
<p>B.h</p>
<pre><code class="language-cpp">#ifdef INCLUDE_B
#define INCLUDE_B

template &lt;class T&gt; class B
{
    public:
        B() { };
        ~B() { };

};

#endif
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1705754</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1705754</guid><dc:creator><![CDATA[gruppa]]></dc:creator><pubDate>Tue, 05 May 2009 10:47:29 GMT</pubDate></item><item><title><![CDATA[Reply to B has not been declared on Tue, 05 May 2009 10:59:00 GMT]]></title><description><![CDATA[<p>Wie wärs mit</p>
<pre><code class="language-cpp">#ifndef INCLUDE_A
//und
#ifndef INCLUDE_B 
//anstatt
#ifdef INCLUDE_A
//und
#ifdef INCLUDE_B
</code></pre>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1705761</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1705761</guid><dc:creator><![CDATA[Tachyon]]></dc:creator><pubDate>Tue, 05 May 2009 10:59:00 GMT</pubDate></item><item><title><![CDATA[Reply to B has not been declared on Tue, 05 May 2009 11:03:20 GMT]]></title><description><![CDATA[<p>eh...das ändert leider nix</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1705764</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1705764</guid><dc:creator><![CDATA[gruppa]]></dc:creator><pubDate>Tue, 05 May 2009 11:03:20 GMT</pubDate></item><item><title><![CDATA[Reply to B has not been declared on Tue, 05 May 2009 11:07:08 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">#include &quot;B.h&quot;

template&lt;class T&gt; inline void
bar(int b, B b) //2 x ein Formalparameter b, und B ist ein Template...

{
//    std::cout &lt;&lt; b &lt;&lt; std::endl;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1705769</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1705769</guid><dc:creator><![CDATA[Tachyon]]></dc:creator><pubDate>Tue, 05 May 2009 11:07:08 GMT</pubDate></item><item><title><![CDATA[Reply to B has not been declared on Tue, 05 May 2009 11:07:17 GMT]]></title><description><![CDATA[<p>Mehrere kleine Fehler, ich fange mal hinten an:<br />
B.h</p>
<pre><code class="language-cpp">#ifdef INCLUDE_B
#define INCLUDE_B

template &lt;class T&gt; class B
{
    public:
        B() { };
        ~B() { };

};

#endif
</code></pre>
<p>Soweit ok.</p>
<p>Impl.h</p>
<pre><code class="language-cpp">#include &quot;B.h&quot;

template&lt;class T&gt; inline void
bar(int b, B b)   // Hier verwendest du 2x den Bezeichner b, was nicht erlaubt ist. Außerdem bezeichnet B alleine keinen Typ, du musst das template spezialisieren, also sowas wie B&lt;T&gt;. 
{
//    std::cout &lt;&lt; b &lt;&lt; std::endl;
}   // hier fehlt ein ;
</code></pre>
<p>A.h</p>
<pre><code class="language-cpp">#include &quot;Impl.h&quot;

#ifdef INCLUDE_A
#define INCLUDE_A

template &lt;class T&gt; class A
{
    public:
     A&lt;T&gt;(int b)  // das &lt;T&gt; ist unnötig
     {
        bar&lt;T&gt;(b);  // Der Konstruktor von bar ist oben anders deklariert. Er nimmt genau zwei Argumente.
     };
     ~A&lt;T&gt;() { }; // hier ist das &lt;T&gt; ebenfalls unnötig

};
#endif
</code></pre>
<p>main.cpp</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &quot;A.h&quot;

int main(int argc, int** argv)
{
    int b = 8;

    A&lt;double&gt; a = A&lt;double&gt;(b);

}
</code></pre>
<p>Wenn du die Änderungen umsetzt, geht's.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1705770</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1705770</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 05 May 2009 11:07:17 GMT</pubDate></item><item><title><![CDATA[Reply to B has not been declared on Tue, 05 May 2009 11:07:49 GMT]]></title><description><![CDATA[<p>eh doch sorry...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1705771</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1705771</guid><dc:creator><![CDATA[gruppa]]></dc:creator><pubDate>Tue, 05 May 2009 11:07:49 GMT</pubDate></item><item><title><![CDATA[Reply to B has not been declared on Tue, 05 May 2009 11:15:10 GMT]]></title><description><![CDATA[<p>ich danke euch für eure Hilfe. Leider funktioniert es bei meinem normalen code nicht obwohl es hier im minimalbeispiel funktioniert. Kann es sein dass die Kompilierreihenfolge eine Rolle spielt? Könnte es dass wenn B.h erst irgendwie nach Impl.h kompiliert wird bzw. nach A.h dass es dann nicht geht?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1705776</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1705776</guid><dc:creator><![CDATA[grupp]]></dc:creator><pubDate>Tue, 05 May 2009 11:15:10 GMT</pubDate></item><item><title><![CDATA[Reply to B has not been declared on Tue, 05 May 2009 11:28:01 GMT]]></title><description><![CDATA[<p>SeppJ schrieb:</p>
<blockquote>
<p>Mehrere kleine Fehler, ich fange mal hinten an:</p>
<pre><code class="language-cpp">#include &quot;B.h&quot;

template&lt;class T&gt; inline void
bar(int b, B b)   // ...
{
//    std::cout &lt;&lt; b &lt;&lt; std::endl;
}   // hier fehlt ein ; MIT SICHERHEIT NICHT!
</code></pre>
</blockquote>
<p>Das Semikolon ist nicht nach dem &quot;}&quot; nötig (Das gilt auch für die Methoden im Header, die eine Implementierung direkt enthalten (Bei der reinen Methoden/Funktionsdeklaration ist es nötig).</p>
<p>Zudem sehe ich sehr viele Fehler in dem Originalcode, werde zeitlich aber nicht darauf eingehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1705786</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1705786</guid><dc:creator><![CDATA[asc]]></dc:creator><pubDate>Tue, 05 May 2009 11:28:01 GMT</pubDate></item><item><title><![CDATA[Reply to B has not been declared on Tue, 05 May 2009 12:35:30 GMT]]></title><description><![CDATA[<p>Ok - nochmal von vorn. Ich hoffe jetzt das Minimalbeispiel so zu haben wie bei meinem großen code:</p>
<ol>
<li>Die main.cpp liegt im obersten Ordner</li>
</ol>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &quot;A.h&quot;

int main(int argc, int** argv)
{
    int b = 8;

    A&lt;double&gt; a = A&lt;double&gt;(b);

}
</code></pre>
<p>Impl.h liegt im Unterordner variante/Impl.h. Also da wo z.B. main.cpp liegt<br />
ist noch ein Ordner variante in dem jetzt Impl.h liegt:</p>
<pre><code class="language-cpp">#include &quot;../B.h&quot;

inline void
bar(int b)
{
//    std::cout &lt;&lt; b &lt;&lt; std::endl;
    }
</code></pre>
<p>Dann die A.h die wieder neben der main.cpp liegt.</p>
<pre><code class="language-cpp">#include &quot;Impl_Env.h&quot;
#include &quot;B.h&quot;

#ifndef INCLUDE_A
#define INCLUDE_A

template &lt;class T&gt; class A
{
    public:
            A&lt;T&gt;(int b);
           ~A&lt;T&gt;() { };

};

#include &quot;A.imp&quot;

#endif
</code></pre>
<p>Und die A.imp die ebenfalls neben der A.h liegt:</p>
<pre><code class="language-cpp">template&lt;class T&gt; 
A&lt;T&gt;::A(int b)
{ 
    bar(b);
};
</code></pre>
<p>Und die B.h die neben der A.h liegt:</p>
<pre><code class="language-cpp">#ifndef INCLUDE_B
#define INCLUDE_B

template &lt;class T&gt; class B
{
    public:
    	B() { };
	~B() { };

};

#endif
</code></pre>
<p>Und schießlich die Impl_Env.h die ebenfalls neben der main.cpp liegt. Sie ist dafür verantwortlich dass auch variante/Impl.h eingebunden wird. Natürlich ist hier nur ein Zweig vorhanden - also immer mit -DFLAG kompilieren.</p>
<pre><code class="language-cpp">#ifdef FLAG
#include &quot;variante/Impl.h&quot;
#endif
</code></pre>
<p>Ich bekomme folgende Fehlermeldung von meinem gcc compiler:</p>
<pre><code>A.imp:4: error: there are no arguments to ‘bar’ that depend on a template parameter, so a declaration of ‘bar’ must be available
</code></pre>
<p>Das ist mir nicht klar weil bar eigentlich vorhanden ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1705839</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1705839</guid><dc:creator><![CDATA[gruppa]]></dc:creator><pubDate>Tue, 05 May 2009 12:35:30 GMT</pubDate></item></channel></rss>