<?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[Kompilierfehler bei boost::regex (diesmal verstaendlich)]]></title><description><![CDATA[<p>Hallo,</p>
<p>nachdem mein letzter Beitrag offenbar nicht wirklich erhellend war, habe ich versucht, das Problem runterzukochen. Das Problem stellt sich nun wie folgt dar: Ich habe zwei Dateien <a href="http://main.cc" rel="nofollow">main.cc</a></p>
<pre><code class="language-cpp">#include &quot;base_nd.h&quot;

int main(int argc, char** argv)
{

}
</code></pre>
<p>und base_nd.h</p>
<pre><code class="language-cpp">#ifndef BASE_NODE_H
#define BASE_NODE_H

#include &lt;boost/regex.hpp&gt;

using namespace boost;

template&lt;class N&gt; class Base_Nd;
template&lt;class N&gt; bool operator==(const Base_Nd&lt;N&gt;&amp; lhs, const Base_Nd&lt;N&gt;&amp; rhs);

template&lt;class N&gt; class Base_Nd
{
	friend bool operator==&lt;N&gt;(const Base_Nd&lt;N&gt;&amp; lhs, const Base_Nd&lt;N&gt;&amp; rhs);
};

template&lt;class N&gt; bool operator==(const Base_Nd&lt;N&gt;&amp; lhs, const Base_Nd&lt;N&gt;&amp; rhs) { return lhs.id() == rhs.id(); }

class Rev_Nd : public virtual Base_Nd&lt;Rev_Nd&gt; { };

#endif
</code></pre>
<p>Wenn ich das kompiliere, erhalte ich die Fehlermeldung</p>
<pre><code class="language-cpp">**** Build of configuration Debug for project GenRecon ****

make all 
Building file: ../main.cc
Invoking: GCC C++ Compiler
g++ -I../../../libs/boost -I../../../libs/gsl/include -I../../../libs/log4cxx/include -I../ -I../src -I../src/classification -I../src/IO -I../src/node -I../src/tree -O0 -g3 -c -fmessage-length=0 -ansi -MMD -MP -MF&quot;main.d&quot; -MT&quot;main.d&quot; -o&quot;main.o&quot; &quot;../main.cc&quot;
In file included from ../main.cc:1:
/usr/include/c++/4.3/bits/stl_iterator_base_types.h: In instantiation of »std::iterator_traits&lt;Rev_Nd&gt;«:
../../../libs/boost/boost/regex/v4/iterator_traits.hpp:116:   instantiated from »boost::re_detail::regex_iterator_traits&lt;Rev_Nd&gt;«
../src/node/base_nd.h:15:   instantiated from »Base_Nd&lt;Rev_Nd&gt;«
../src/node/base_nd.h:22:   instantiated from here
/usr/include/c++/4.3/bits/stl_iterator_base_types.h:133: Fehler: invalid use of incomplete type »class Rev_Nd«
../src/node/base_nd.h:22: Fehler: forward declaration of »class Rev_Nd«
/usr/include/c++/4.3/bits/stl_iterator_base_types.h:134: Fehler: invalid use of incomplete type »class Rev_Nd«
../src/node/base_nd.h:22: Fehler: forward declaration of »class Rev_Nd«
/usr/include/c++/4.3/bits/stl_iterator_base_types.h:135: Fehler: invalid use of incomplete type »class Rev_Nd«
../src/node/base_nd.h:22: Fehler: forward declaration of »class Rev_Nd«
/usr/include/c++/4.3/bits/stl_iterator_base_types.h:136: Fehler: invalid use of incomplete type »class Rev_Nd«
../src/node/base_nd.h:22: Fehler: forward declaration of »class Rev_Nd«
/usr/include/c++/4.3/bits/stl_iterator_base_types.h:137: Fehler: invalid use of incomplete type »class Rev_Nd«
../src/node/base_nd.h:22: Fehler: forward declaration of »class Rev_Nd«
make: *** [main.o] Fehler 1
</code></pre>
<p>Verwendung der folgenden beiden Versionen von base_nd.h fuehrt zu fehlerfreien Kompilieren (einziger Unterschied zum Original besteht in den auskommentierten Zeilen):</p>
<pre><code class="language-cpp">#ifndef BASE_NODE_H
#define BASE_NODE_H

#include &lt;boost/regex.hpp&gt;

//using namespace boost;

template&lt;class N&gt; class Base_Nd;
template&lt;class N&gt; bool operator==(const Base_Nd&lt;N&gt;&amp; lhs, const Base_Nd&lt;N&gt;&amp; rhs);

template&lt;class N&gt; class Base_Nd
{
	friend bool operator==&lt;N&gt;(const Base_Nd&lt;N&gt;&amp; lhs, const Base_Nd&lt;N&gt;&amp; rhs);
};

template&lt;class N&gt; bool operator==(const Base_Nd&lt;N&gt;&amp; lhs, const Base_Nd&lt;N&gt;&amp; rhs) { return lhs.id() == rhs.id(); }

class Rev_Nd : public virtual Base_Nd&lt;Rev_Nd&gt; { };

#endif
</code></pre>
<p>und</p>
<pre><code class="language-cpp">#ifndef BASE_NODE_H
#define BASE_NODE_H

#include &lt;boost/regex.hpp&gt;

using namespace boost;

template&lt;class N&gt; class Base_Nd;
template&lt;class N&gt; bool operator==(const Base_Nd&lt;N&gt;&amp; lhs, const Base_Nd&lt;N&gt;&amp; rhs);

template&lt;class N&gt; class Base_Nd
{
	//friend bool operator==&lt;N&gt;(const Base_Nd&lt;N&gt;&amp; lhs, const Base_Nd&lt;N&gt;&amp; rhs);
};

//template&lt;class N&gt; bool operator==(const Base_Nd&lt;N&gt;&amp; lhs, const Base_Nd&lt;N&gt;&amp; rhs) { return lhs.id() == rhs.id(); }

class Rev_Nd : public virtual Base_Nd&lt;Rev_Nd&gt; { };

#endif
</code></pre>
<p>Weiss jemand, was hier das Problem ist?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/240820/kompilierfehler-bei-boost-regex-diesmal-verstaendlich</link><generator>RSS for Node</generator><lastBuildDate>Mon, 21 Sep 2026 19:46:19 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/240820.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 12 May 2009 08:02:14 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Kompilierfehler bei boost::regex (diesmal verstaendlich) on Tue, 12 May 2009 08:02:14 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>nachdem mein letzter Beitrag offenbar nicht wirklich erhellend war, habe ich versucht, das Problem runterzukochen. Das Problem stellt sich nun wie folgt dar: Ich habe zwei Dateien <a href="http://main.cc" rel="nofollow">main.cc</a></p>
<pre><code class="language-cpp">#include &quot;base_nd.h&quot;

int main(int argc, char** argv)
{

}
</code></pre>
<p>und base_nd.h</p>
<pre><code class="language-cpp">#ifndef BASE_NODE_H
#define BASE_NODE_H

#include &lt;boost/regex.hpp&gt;

using namespace boost;

template&lt;class N&gt; class Base_Nd;
template&lt;class N&gt; bool operator==(const Base_Nd&lt;N&gt;&amp; lhs, const Base_Nd&lt;N&gt;&amp; rhs);

template&lt;class N&gt; class Base_Nd
{
	friend bool operator==&lt;N&gt;(const Base_Nd&lt;N&gt;&amp; lhs, const Base_Nd&lt;N&gt;&amp; rhs);
};

template&lt;class N&gt; bool operator==(const Base_Nd&lt;N&gt;&amp; lhs, const Base_Nd&lt;N&gt;&amp; rhs) { return lhs.id() == rhs.id(); }

class Rev_Nd : public virtual Base_Nd&lt;Rev_Nd&gt; { };

#endif
</code></pre>
<p>Wenn ich das kompiliere, erhalte ich die Fehlermeldung</p>
<pre><code class="language-cpp">**** Build of configuration Debug for project GenRecon ****

make all 
Building file: ../main.cc
Invoking: GCC C++ Compiler
g++ -I../../../libs/boost -I../../../libs/gsl/include -I../../../libs/log4cxx/include -I../ -I../src -I../src/classification -I../src/IO -I../src/node -I../src/tree -O0 -g3 -c -fmessage-length=0 -ansi -MMD -MP -MF&quot;main.d&quot; -MT&quot;main.d&quot; -o&quot;main.o&quot; &quot;../main.cc&quot;
In file included from ../main.cc:1:
/usr/include/c++/4.3/bits/stl_iterator_base_types.h: In instantiation of »std::iterator_traits&lt;Rev_Nd&gt;«:
../../../libs/boost/boost/regex/v4/iterator_traits.hpp:116:   instantiated from »boost::re_detail::regex_iterator_traits&lt;Rev_Nd&gt;«
../src/node/base_nd.h:15:   instantiated from »Base_Nd&lt;Rev_Nd&gt;«
../src/node/base_nd.h:22:   instantiated from here
/usr/include/c++/4.3/bits/stl_iterator_base_types.h:133: Fehler: invalid use of incomplete type »class Rev_Nd«
../src/node/base_nd.h:22: Fehler: forward declaration of »class Rev_Nd«
/usr/include/c++/4.3/bits/stl_iterator_base_types.h:134: Fehler: invalid use of incomplete type »class Rev_Nd«
../src/node/base_nd.h:22: Fehler: forward declaration of »class Rev_Nd«
/usr/include/c++/4.3/bits/stl_iterator_base_types.h:135: Fehler: invalid use of incomplete type »class Rev_Nd«
../src/node/base_nd.h:22: Fehler: forward declaration of »class Rev_Nd«
/usr/include/c++/4.3/bits/stl_iterator_base_types.h:136: Fehler: invalid use of incomplete type »class Rev_Nd«
../src/node/base_nd.h:22: Fehler: forward declaration of »class Rev_Nd«
/usr/include/c++/4.3/bits/stl_iterator_base_types.h:137: Fehler: invalid use of incomplete type »class Rev_Nd«
../src/node/base_nd.h:22: Fehler: forward declaration of »class Rev_Nd«
make: *** [main.o] Fehler 1
</code></pre>
<p>Verwendung der folgenden beiden Versionen von base_nd.h fuehrt zu fehlerfreien Kompilieren (einziger Unterschied zum Original besteht in den auskommentierten Zeilen):</p>
<pre><code class="language-cpp">#ifndef BASE_NODE_H
#define BASE_NODE_H

#include &lt;boost/regex.hpp&gt;

//using namespace boost;

template&lt;class N&gt; class Base_Nd;
template&lt;class N&gt; bool operator==(const Base_Nd&lt;N&gt;&amp; lhs, const Base_Nd&lt;N&gt;&amp; rhs);

template&lt;class N&gt; class Base_Nd
{
	friend bool operator==&lt;N&gt;(const Base_Nd&lt;N&gt;&amp; lhs, const Base_Nd&lt;N&gt;&amp; rhs);
};

template&lt;class N&gt; bool operator==(const Base_Nd&lt;N&gt;&amp; lhs, const Base_Nd&lt;N&gt;&amp; rhs) { return lhs.id() == rhs.id(); }

class Rev_Nd : public virtual Base_Nd&lt;Rev_Nd&gt; { };

#endif
</code></pre>
<p>und</p>
<pre><code class="language-cpp">#ifndef BASE_NODE_H
#define BASE_NODE_H

#include &lt;boost/regex.hpp&gt;

using namespace boost;

template&lt;class N&gt; class Base_Nd;
template&lt;class N&gt; bool operator==(const Base_Nd&lt;N&gt;&amp; lhs, const Base_Nd&lt;N&gt;&amp; rhs);

template&lt;class N&gt; class Base_Nd
{
	//friend bool operator==&lt;N&gt;(const Base_Nd&lt;N&gt;&amp; lhs, const Base_Nd&lt;N&gt;&amp; rhs);
};

//template&lt;class N&gt; bool operator==(const Base_Nd&lt;N&gt;&amp; lhs, const Base_Nd&lt;N&gt;&amp; rhs) { return lhs.id() == rhs.id(); }

class Rev_Nd : public virtual Base_Nd&lt;Rev_Nd&gt; { };

#endif
</code></pre>
<p>Weiss jemand, was hier das Problem ist?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1709308</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1709308</guid><dc:creator><![CDATA[ingobulla]]></dc:creator><pubDate>Tue, 12 May 2009 08:02:14 GMT</pubDate></item><item><title><![CDATA[Reply to Kompilierfehler bei boost::regex (diesmal verstaendlich) on Tue, 12 May 2009 12:06:25 GMT]]></title><description><![CDATA[<p>Das Problem ist relativ eindeutig. Durch <code>using namespace boost;</code> wird der Namensraum <code>boost</code> in den globalen Namensraum eingebunden. Dadurch werden verschiedene zusätzliche <code>operator ==</code> zur Verfügung gestellt. Anscheinend findet der Kompiler dann einen besser passenden <code>operator ==</code> , als welchen du möchtest. Also wird der falsche <code>operator ==</code> instanziert, welcher ein <code>boost::re_detail::regex_iterator_traits</code> beinhaltet. Diese Klasse ist von <code>std::iterator_traits</code> abgeleitet und das gibt dann schlussendlich den Kompilerfehler.</p>
<p>Das grundsätzliche Problem liegt also in deiner unvorsichtigen Verwendung von <code>using namespace</code> . Deswegen warnen hier verschiedene Leute immer wieder vor der unachtsamen Verwendung. Erst recht hat so ein <code>using namespace</code> nichts in einem Header verloren. Diese Anweisung hebelt die Funktion des Namensraumes aus.</p>
<p>[Unwichtiger Zusatz]<br />
Mir ist leider nicht ganz klar, wieso der Kompiler hier eine bessere Möglichkeit findet, denn ich selber finde im Namensraum <code>boost</code> keinen besser passenden <code>operator ==</code> . Der Namensraum ist allerdings auch verdammt gross, kann gut sein, dass ich beim Suchen den einen oder anderen <code>operator ==</code> übersehen habe.<br />
VC2008 kompiliert den Code einwandfrei, konnte den Fehler nur mit dem g++ reproduzieren. Mir ist nicht ganz klar, ob es ein Bug im g++ ist oder VC2008 sich nicht ganz korrekt an den Standard hält, was ziemlich üblich wäre.<br />
[/Unwichtiger Zusatz]</p>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1709388</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1709388</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Tue, 12 May 2009 12:06:25 GMT</pubDate></item></channel></rss>