<?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[zirkuläre Abhängigkeit auflösen]]></title><description><![CDATA[<p>also ich hab das Problem mal wie folgt abstrahiert (liefert die gleiche Fehlermeldung)</p>
<pre><code class="language-cpp">//header h0.h
#ifndef __h0_h__
#define __h0_h__

#include &quot;h1.h&quot;

namespace n0
{
	class h0
	{
		public:
			n1::h1 _dep;
			void set_dep(n1::h1 dep);
	};
};

#endif

//cpp h0.cpp
#ifndef __h0_cpp__
#define __h0_cpp__

#include &quot;h0.h&quot;

void n0::h0::set_dep(n1::h1 dep)
{
	_dep = dep;
}

#endif
</code></pre>
<pre><code class="language-cpp">//header h1.h
#ifndef __h1_h__
#define __h1_h__

#include &quot;h2.h&quot;

namespace n1
{
	class h1
	{
		public:
			n2::h2 _dep;
			void set_dep(n2::h2 dep);
	};
};

#endif

//cpp h1.cpp
#ifndef __h1_cpp__
#define __h1_cpp__

#include &quot;h1.h&quot;

void n0::h0::set_dep(n2::h2 dep)
{
	_dep = dep;
}

#endif
</code></pre>
<pre><code class="language-cpp">//header h2.h
#ifndef __h2_h__
#define __h2_h__

#include &quot;h0.h&quot;

namespace n2
{
	class h2
	{
		public:
			n0::h0 _dep;
			void set_dep(n0::h0 dep);
	};
};

#endif

//cpp h2.cpp
#ifndef __h2_cpp__
#define __h2_cpp__

#include &quot;h2.h&quot;

void n2::h2::set_dep(n0::h0 dep)
{
	_dep = dep;
}

#endif
</code></pre>
<pre><code class="language-cpp">#include &quot;h0.h&quot;
#include &quot;h1.h&quot;
#include &quot;h2.h&quot;

int main()
{
	n0::h0 o0;
	n1::h1 o1;
	n2::h2 o2;
	return 0;
};
</code></pre>
<p>wie man sieht besteht eine zirkuläre abhängikeit h0-&gt;h1-&gt;h2-&gt;h0. normalerweise löst man das ja damit das man eine der klassen schon vorher deklariert und später näher ausführt aber irgendwie klappt das hier nicht</p>
<p>wenn ich den h0.h header z.B. wie folgt ändere:</p>
<pre><code class="language-cpp">#ifndef __h0_h__
#define __h0_h__

namespace n1
{
	class h1;
}

namespace n2
{
	class h2;
}

namespace n0
{
	class h0
	{
		public:
			n1::h1 _dep;
			void set_dep(n1::h1 dep);
	};
};

#include &quot;h1.h&quot;
</code></pre>
<p>bekomme ich die Fehlermeldung:</p>
<pre><code>error C2079: 'n0::h0::_dep' verwendet undefiniertes class 'n1::h1'
</code></pre>
<p>also ich wäre für jede Hilfe dankbar, weiß nämlich nicht mehr weiter.<br />
Danke schonmal im Voraus</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/240020/zirkuläre-abhängigkeit-auflösen</link><generator>RSS for Node</generator><lastBuildDate>Tue, 22 Sep 2026 06:11:37 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/240020.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 30 Apr 2009 17:13:02 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to zirkuläre Abhängigkeit auflösen on Thu, 30 Apr 2009 17:13:02 GMT]]></title><description><![CDATA[<p>also ich hab das Problem mal wie folgt abstrahiert (liefert die gleiche Fehlermeldung)</p>
<pre><code class="language-cpp">//header h0.h
#ifndef __h0_h__
#define __h0_h__

#include &quot;h1.h&quot;

namespace n0
{
	class h0
	{
		public:
			n1::h1 _dep;
			void set_dep(n1::h1 dep);
	};
};

#endif

//cpp h0.cpp
#ifndef __h0_cpp__
#define __h0_cpp__

#include &quot;h0.h&quot;

void n0::h0::set_dep(n1::h1 dep)
{
	_dep = dep;
}

#endif
</code></pre>
<pre><code class="language-cpp">//header h1.h
#ifndef __h1_h__
#define __h1_h__

#include &quot;h2.h&quot;

namespace n1
{
	class h1
	{
		public:
			n2::h2 _dep;
			void set_dep(n2::h2 dep);
	};
};

#endif

//cpp h1.cpp
#ifndef __h1_cpp__
#define __h1_cpp__

#include &quot;h1.h&quot;

void n0::h0::set_dep(n2::h2 dep)
{
	_dep = dep;
}

#endif
</code></pre>
<pre><code class="language-cpp">//header h2.h
#ifndef __h2_h__
#define __h2_h__

#include &quot;h0.h&quot;

namespace n2
{
	class h2
	{
		public:
			n0::h0 _dep;
			void set_dep(n0::h0 dep);
	};
};

#endif

//cpp h2.cpp
#ifndef __h2_cpp__
#define __h2_cpp__

#include &quot;h2.h&quot;

void n2::h2::set_dep(n0::h0 dep)
{
	_dep = dep;
}

#endif
</code></pre>
<pre><code class="language-cpp">#include &quot;h0.h&quot;
#include &quot;h1.h&quot;
#include &quot;h2.h&quot;

int main()
{
	n0::h0 o0;
	n1::h1 o1;
	n2::h2 o2;
	return 0;
};
</code></pre>
<p>wie man sieht besteht eine zirkuläre abhängikeit h0-&gt;h1-&gt;h2-&gt;h0. normalerweise löst man das ja damit das man eine der klassen schon vorher deklariert und später näher ausführt aber irgendwie klappt das hier nicht</p>
<p>wenn ich den h0.h header z.B. wie folgt ändere:</p>
<pre><code class="language-cpp">#ifndef __h0_h__
#define __h0_h__

namespace n1
{
	class h1;
}

namespace n2
{
	class h2;
}

namespace n0
{
	class h0
	{
		public:
			n1::h1 _dep;
			void set_dep(n1::h1 dep);
	};
};

#include &quot;h1.h&quot;
</code></pre>
<p>bekomme ich die Fehlermeldung:</p>
<pre><code>error C2079: 'n0::h0::_dep' verwendet undefiniertes class 'n1::h1'
</code></pre>
<p>also ich wäre für jede Hilfe dankbar, weiß nämlich nicht mehr weiter.<br />
Danke schonmal im Voraus</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1703761</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1703761</guid><dc:creator><![CDATA[StarCraftFeuerteufel]]></dc:creator><pubDate>Thu, 30 Apr 2009 17:13:02 GMT</pubDate></item><item><title><![CDATA[Reply to zirkuläre Abhängigkeit auflösen on Thu, 30 Apr 2009 18:23:26 GMT]]></title><description><![CDATA[<p>In dieser Art nicht möglich. Mit einer Vorwärtsdeklaration kann man nur Zeiger und Referenzen definieren. Keine Objekte erstellen und keine Methoden aufrufen, dazu muss die ganze Klasse bekannt sein.</p>
<p>Daher könntest du zum Beispiel einen Zeiger nehmen und dann in der <code>*.cpp</code> im Konstruktor per <code>new</code> ein Objekt erstellen. Das würde funktionieren. In der <code>*.cpp</code> muss dann allerdings die Klasse vollständig bekannt sein.</p>
<p>Aber ich würde mir eher nochmals Gedanken zum Design machen. Sowas ist eher unüblich.</p>
<p>Grüssli</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1703825</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1703825</guid><dc:creator><![CDATA[Dravere]]></dc:creator><pubDate>Thu, 30 Apr 2009 18:23:26 GMT</pubDate></item><item><title><![CDATA[Reply to zirkuläre Abhängigkeit auflösen on Thu, 30 Apr 2009 18:28:11 GMT]]></title><description><![CDATA[<p>schonmal gut zu wissen das es nicht geht, dann werde ich mir wohl was anderes einfallen lassen müssen. danke trotzdem</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1703829</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1703829</guid><dc:creator><![CDATA[StarCraftFeuerteufel]]></dc:creator><pubDate>Thu, 30 Apr 2009 18:28:11 GMT</pubDate></item></channel></rss>