<?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[C2027 in Struct]]></title><description><![CDATA[<p>Hallo.</p>
<p>Ich nutze structs mit Funktionen. Dabei bekomme ich einen<br />
Compilerfehler C2027.</p>
<p>Folgendes Codebeispiel:</p>
<pre><code>#include &lt;stdio.h&gt;;

typedef struct Type1 {
	struct Type2* T2;

	Type1(){}

	void DoSomething1() {
		printf(&quot;Type1!\n&quot;);
	}

	void DoSomethingElse1() {
		T2-&gt;DoSomething2(); /*ERROR: C2027*/
	}
}Type1;

typedef struct Type2 {
	struct Type1* T1;

	Type2(){}

	void DoSomething2() {
		printf(&quot;Type2!\n&quot;);
	}

	void DoSomethingElse2() {
		T1-&gt;DoSomething1();
	}
}Type2;

int main() {
	Type1 T1;
	Type2 T2;

	T1.T2 = &amp;T2;
	T2.T1 = &amp;T1;
}
</code></pre>
<p>Kann ich das irgendwie umgehen? Ich dachte, der Zeigerzugriff ist auch<br />
bei nicht vollständig definierten Typen erlaubt.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/340096/c2027-in-struct</link><generator>RSS for Node</generator><lastBuildDate>Sat, 11 Apr 2026 10:46:07 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/340096.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 19 Oct 2016 11:21:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to C2027 in Struct on Wed, 19 Oct 2016 11:21:08 GMT]]></title><description><![CDATA[<p>Hallo.</p>
<p>Ich nutze structs mit Funktionen. Dabei bekomme ich einen<br />
Compilerfehler C2027.</p>
<p>Folgendes Codebeispiel:</p>
<pre><code>#include &lt;stdio.h&gt;;

typedef struct Type1 {
	struct Type2* T2;

	Type1(){}

	void DoSomething1() {
		printf(&quot;Type1!\n&quot;);
	}

	void DoSomethingElse1() {
		T2-&gt;DoSomething2(); /*ERROR: C2027*/
	}
}Type1;

typedef struct Type2 {
	struct Type1* T1;

	Type2(){}

	void DoSomething2() {
		printf(&quot;Type2!\n&quot;);
	}

	void DoSomethingElse2() {
		T1-&gt;DoSomething1();
	}
}Type2;

int main() {
	Type1 T1;
	Type2 T2;

	T1.T2 = &amp;T2;
	T2.T1 = &amp;T1;
}
</code></pre>
<p>Kann ich das irgendwie umgehen? Ich dachte, der Zeigerzugriff ist auch<br />
bei nicht vollständig definierten Typen erlaubt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2512076</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2512076</guid><dc:creator><![CDATA[CJens]]></dc:creator><pubDate>Wed, 19 Oct 2016 11:21:08 GMT</pubDate></item><item><title><![CDATA[Reply to C2027 in Struct on Wed, 19 Oct 2016 11:31:18 GMT]]></title><description><![CDATA[<p>CJens schrieb:</p>
<blockquote>
<p>Kann ich das irgendwie umgehen?</p>
</blockquote>
<p>Ja, du kannst das Problem umgehen, indem du mit Vorwärtsdeklarationen arbeitest und den Code sauber in Header- und Sourcedateien aufteilst.</p>
<p>// edit</p>
<p>Für alle die die Fehlercodes vom MS Compiler nicht auswendig können:<br />
C2027 bedeutet &quot;use of undefined type 'type'&quot;, siehe <a href="https://msdn.microsoft.com/en-us/library/6c2dk0ah.aspx" rel="nofollow">https://msdn.microsoft.com/en-us/library/6c2dk0ah.aspx</a></p>
<p>// edit2</p>
<p>Die Verwendung von <code>typedef struct</code> bei der Deklaration und <code>struct X</code> bei der Verwendung sind überflüssig in C++ und rühren von C her.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2512077</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2512077</guid><dc:creator><![CDATA[theta]]></dc:creator><pubDate>Wed, 19 Oct 2016 11:31:18 GMT</pubDate></item><item><title><![CDATA[Reply to C2027 in Struct on Wed, 19 Oct 2016 11:33:33 GMT]]></title><description><![CDATA[<p>Vorwärtsdeklaration hat hier nicht funktioniert:</p>
<pre><code>#include &lt;stdio.h&gt;;

typedef struct Type1;
typedef struct Type2;

typedef struct Type1 {
	struct Type2* T2 = NULL;

	Type1() { T2 = NULL; }

	void DoSomething1() {
		printf(&quot;Type1!\n&quot;);
	}

	void DoSomethingElse1() {
		T2-&gt;DoSomething2(); /*ERROR: C2027*/
	}
}Type1;

typedef struct Type2 {
	struct Type1* T1 = NULL;

	Type2() { T1 = NULL; }

	void DoSomething2() {
		printf(&quot;Type2!\n&quot;);
	}

	void DoSomethingElse2() {
		T1-&gt;DoSomething1();
	}
}Type2;

int main() {
	Type1 T1;
	Type2 T2;

	T1.T2 = &amp;T2;
	T2.T1 = &amp;T1;
}
</code></pre>
<p>Der Fehler besteht weiterhin.</p>
<p>Das hier ist natürlich nur ein einfaches Beispiel um den Fehler zu reproduzieren. In meinem tatsächlichen Projekt hat jede Struktur eine eigene Header, die in der Source-Datei eingebunden wird.</p>
<p>Ja, das war tatsächlich ein Projekt, welches ich ursprünglich in C geschrieben hatte und jetzt portiere - da hab ich mir das typedef angewöhnt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2512078</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2512078</guid><dc:creator><![CDATA[CJens]]></dc:creator><pubDate>Wed, 19 Oct 2016 11:33:33 GMT</pubDate></item><item><title><![CDATA[Reply to C2027 in Struct on Wed, 19 Oct 2016 11:35:13 GMT]]></title><description><![CDATA[<p>Was auch zu erwähnen ist, ich aber dachte, dass sei klar:<br />
<code>T2</code> und <code>T1</code> müssen natürlich auf ein Objekt zeigen, bevor <code>DoSomething...()</code> aufgerufen wird. Aber das ergibt nur Probleme zur Laufzeit, nicht zur Compiletime.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2512079</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2512079</guid><dc:creator><![CDATA[theta]]></dc:creator><pubDate>Wed, 19 Oct 2016 11:35:13 GMT</pubDate></item><item><title><![CDATA[Reply to C2027 in Struct on Wed, 19 Oct 2016 11:37:46 GMT]]></title><description><![CDATA[<p>Das ist klar.</p>
<p>Wie gesagt, ist nur ein einfaches Beispiel. Es handelt sich ja um einen Compilerfehler. Es ist dem Beispiel ja nicht dienlich, wenn ich es aufblase und vorher noch eine Abfrage einbaue, welche prüft ob T1 bzw. T2 == NULL sind.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2512080</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2512080</guid><dc:creator><![CDATA[CJens]]></dc:creator><pubDate>Wed, 19 Oct 2016 11:37:46 GMT</pubDate></item><item><title><![CDATA[Reply to C2027 in Struct on Wed, 19 Oct 2016 11:41:22 GMT]]></title><description><![CDATA[<p>Vielleicht hast du in den entsprechenden Sourcedateien vergessen die entsprechende Headerdatei zu inkludieren?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2512081</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2512081</guid><dc:creator><![CDATA[theta]]></dc:creator><pubDate>Wed, 19 Oct 2016 11:41:22 GMT</pubDate></item><item><title><![CDATA[Reply to C2027 in Struct on Wed, 19 Oct 2016 11:43:47 GMT]]></title><description><![CDATA[<p>In meinem einfachen Beispiel gibt es keine Header Dateien.</p>
<p>Bei Header-Include kopiert er doch nur den Text rein.</p>
<p>Ich möchte dieses einfache Beispiel zum Laufen bringen. Dann kann ich es auf mein Programm übertragen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2512083</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2512083</guid><dc:creator><![CDATA[CJens]]></dc:creator><pubDate>Wed, 19 Oct 2016 11:43:47 GMT</pubDate></item><item><title><![CDATA[Reply to C2027 in Struct on Wed, 19 Oct 2016 11:55:04 GMT]]></title><description><![CDATA[<p>Hier ein kleines Beispiel:</p>
<p><code>main.cpp</code></p>
<pre><code>#include &quot;X.hpp&quot;
#include &quot;Y.hpp&quot;

int main()
{
    X x;
    Y y;

    x.y = &amp;y;
    y.x = &amp;x;

    x.say_hello_to_y();
    y.say_hello_to_x();
}
</code></pre>
<p><code>X.hpp</code></p>
<pre><code>#ifndef HEADER_X_HPP
#define HEADER_X_HPP

struct Y;

struct X
{
    Y* y = nullptr;
    void say_hello_to_y();
    void hello_from_y();
};

#endif
</code></pre>
<p><code>X.cpp</code></p>
<pre><code>#include &quot;X.hpp&quot;
#include &quot;Y.hpp&quot;

#include &lt;iostream&gt;
#include &lt;cassert&gt;

void X::say_hello_to_y()
{
    assert(y != nullptr);
    y-&gt;hello_from_x();
}

void X::hello_from_y()
{
    std::cout &lt;&lt; &quot;Hello from Y\n&quot;;
}
</code></pre>
<p><code>Y.hpp</code></p>
<pre><code>#ifndef HEADER_Y_HPP
#define HEADER_Y_HPP

struct X;

struct Y
{
    X* x = nullptr;
    void say_hello_to_x();
    void hello_from_x();
};

#endif
</code></pre>
<p><code>Y.cpp</code></p>
<pre><code>#include &quot;Y.hpp&quot;
#include &quot;X.hpp&quot;

#include &lt;iostream&gt;
#include &lt;cassert&gt;

void Y::say_hello_to_x()
{
    assert(x != nullptr);
    x-&gt;hello_from_y();
}

void Y::hello_from_x()
{
    std::cout &lt;&lt; &quot;Hello from X\n&quot;;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2512084</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2512084</guid><dc:creator><![CDATA[theta]]></dc:creator><pubDate>Wed, 19 Oct 2016 11:55:04 GMT</pubDate></item><item><title><![CDATA[Reply to C2027 in Struct on Wed, 19 Oct 2016 12:03:32 GMT]]></title><description><![CDATA[<p>CJens schrieb:</p>
<blockquote>
<p>In meinem einfachen Beispiel gibt es keine Header Dateien.</p>
<p>Bei Header-Include kopiert er doch nur den Text rein.</p>
<p>Ich möchte dieses einfache Beispiel zum Laufen bringen. Dann kann ich es auf mein Programm übertragen.</p>
</blockquote>
<p>Dann zeig am besten den (Beispiel-) Code, der nicht läuft. Falls das der Code aus deinem ersten Beitrag war, korrigiere ihn bezüglich Vorwärtsdekl. und Unterteilung in Header und Sourcen. Dann zeige ihn wieder mit der kopierten Fehlermeldung.</p>
<p>// edit</p>
<p>Falls es sich um den Code aus deinem 2. Beitrag handelt musst du ihn in verschiedene Source-Dateien aufteilen und die entsprechenden struct-Definitionen (die normalerweise inkludiert werden) in diese Source-Dateien hineinschreiben (wenn du keine Header hast/willst).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2512085</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2512085</guid><dc:creator><![CDATA[theta]]></dc:creator><pubDate>Wed, 19 Oct 2016 12:03:32 GMT</pubDate></item><item><title><![CDATA[Reply to C2027 in Struct on Wed, 19 Oct 2016 12:11:43 GMT]]></title><description><![CDATA[<p>Übertragen auf mein Beispiel:</p>
<p>StructTest.cpp</p>
<pre><code>#include &lt;stdio.h&gt;;

#ifndef STRUCT_TYPE_2
	#include &quot;Type2_Struct.h&quot;;
#endif

#ifndef STRUCT_TYPE_1
	#include &quot;Type1_Struct.h&quot;;
#endif

int main() {
	struct Type1 T1;
	struct Type2 T2;

	T1.T2 = &amp;T2;
	T2.T1 = &amp;T1;
}
</code></pre>
<p>Type1_Struct.h</p>
<pre><code>#define STRUCT_TYPE_1

struct Type2;

struct Type1 {
	struct Type2* T2 = NULL;

	Type1() { T2 = NULL; }

	void DoSomething1() {
		printf(&quot;Type1!\n&quot;);
	}

	void DoSomethingElse1() {
		T2-&gt;DoSomething2();
	}
}Type1;
</code></pre>
<p>Type2_struct.h</p>
<pre><code>#define STRUCT_TYPE_2

struct Type1;

struct Type2 {
	struct Type1* T1 = NULL;

	Type2() { T1 = NULL; }

	void DoSomething2() {
		printf(&quot;Type2!\n&quot;);
	}

	void DoSomethingElse2() {
		T1-&gt;DoSomething1(); /*ERROR: C2027*/
	}
}Type2;
</code></pre>
<p>Den Compilerfehler bekomme ich aber noch immer.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2512087</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2512087</guid><dc:creator><![CDATA[CJens]]></dc:creator><pubDate>Wed, 19 Oct 2016 12:11:43 GMT</pubDate></item><item><title><![CDATA[Reply to C2027 in Struct on Wed, 19 Oct 2016 12:12:30 GMT]]></title><description><![CDATA[<p>CJens schrieb:</p>
<blockquote>
<p>Vorwärtsdeklaration hat hier nicht funktioniert:<br />
...<br />
Der Fehler besteht weiterhin.</p>
</blockquote>
<p>Vorwärtsdeklaration ist nur der eine Teil. Du kannst T2 erst benutzen, wenn die Deklaration von Type2 bekannt ist, d.h. die <strong>Definition</strong> von DoSomethingElse1() muss nach der struct Type2 erfolgen.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;

struct Type2;

struct Type1 {
  Type2* T2 = nullptr;

  void DoSomething1() {
    std::cout &lt;&lt; &quot;Type1!\n&quot;;
  }

  void DoSomethingElse1();
};

struct Type2 {
  Type1* T1 = nullptr;

  void DoSomething2() {
    std::cout &lt;&lt; &quot;Type2!\n&quot;;
  }

  void DoSomethingElse2() {
    T1-&gt;DoSomething1();
  }
};

void Type1::DoSomethingElse1() {
  T2-&gt;DoSomething2();
}

int main() {
  Type1 T1;
  Type2 T2;

  T1.T2 = &amp;T2;
  T2.T1 = &amp;T1;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2512088</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2512088</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Wed, 19 Oct 2016 12:12:30 GMT</pubDate></item><item><title><![CDATA[Reply to C2027 in Struct on Wed, 19 Oct 2016 12:14:36 GMT]]></title><description><![CDATA[<p>CJens schrieb:</p>
<blockquote>
<pre><code>#ifndef STRUCT_TYPE_2
	#include &quot;Type2_Struct.h&quot;;
#endif

#ifndef STRUCT_TYPE_1
	#include &quot;Type1_Struct.h&quot;;
#endif
</code></pre>
</blockquote>
<p>Includeguards gehören in den Header.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2512090</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2512090</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Wed, 19 Oct 2016 12:14:36 GMT</pubDate></item><item><title><![CDATA[Reply to C2027 in Struct on Wed, 19 Oct 2016 12:26:14 GMT]]></title><description><![CDATA[<p>Super, danke. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /> <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
<p>StructTest.cpp</p>
<pre><code>#include &lt;stdio.h&gt;;

#ifndef STRUCT_TYPE_2
	#include &quot;Type2_Struct.h&quot;;
#endif

#ifndef STRUCT_TYPE_1
	#include &quot;Type1_Struct.h&quot;;
#endif

#ifndef STRUCT_FUNCTIONS
	#include &quot;Functions.h&quot;;
#endif

int main() {
	struct Type1 T1;
	struct Type2 T2;

	T1.T2 = &amp;T2;
	T2.T1 = &amp;T1;
}
</code></pre>
<p>Type1.h</p>
<pre><code>#define STRUCT_TYPE_1

struct Type2;

struct Type1 {
	struct Type2* T2 = NULL;

	Type1() { T2 = NULL; }

	void DoSomething1();
	void DoSomethingElse1();
}Type1;
</code></pre>
<p>Type2.h</p>
<pre><code>#define STRUCT_TYPE_2

struct Type1;

struct Type2 {
	struct Type1* T1 = NULL;

	Type2() { T1 = NULL; }

	void DoSomething2();
	void DoSomethingElse2();
}Type2;
</code></pre>
<p>Functions.h</p>
<pre><code>#define STRUCT_FUNCTIONS

void Type1::DoSomethingElse1() { T2-&gt;DoSomething2(); }
void Type1::DoSomething1() { printf(&quot;Type1!\n&quot;); }

void Type2::DoSomething2() { printf(&quot;Type2!\n&quot;); }
void Type2::DoSomethingElse2() { T1-&gt;DoSomething1(); }
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2512093</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2512093</guid><dc:creator><![CDATA[CJens]]></dc:creator><pubDate>Wed, 19 Oct 2016 12:26:14 GMT</pubDate></item><item><title><![CDATA[Reply to C2027 in Struct on Wed, 19 Oct 2016 12:27:00 GMT]]></title><description><![CDATA[<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f644.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_rolling_eyes"
      title=":rolling_eyes:"
      alt="🙄"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2512094</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2512094</guid><dc:creator><![CDATA[theta]]></dc:creator><pubDate>Wed, 19 Oct 2016 12:27:00 GMT</pubDate></item><item><title><![CDATA[Reply to C2027 in Struct on Wed, 19 Oct 2016 12:29:40 GMT]]></title><description><![CDATA[<p>CJens schrieb:</p>
<blockquote>
<p>Functions.h</p>
<pre><code>#define STRUCT_FUNCTIONS

void Type1::DoSomethingElse1() { T2-&gt;DoSomething2(); }
void Type1::DoSomething1() { printf(&quot;Type1!\n&quot;); }

void Type2::DoSomething2() { printf(&quot;Type2!\n&quot;); }
void Type2::DoSomethingElse2() { T1-&gt;DoSomething1(); }
</code></pre>
</blockquote>
<p><strong>NEIIIIIIN!</strong> cpp!</p>
<p><strong>INCLUDEGUARDS GEHÖREN IN DEN HEADER! AUCH IN C</strong></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2512097</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2512097</guid><dc:creator><![CDATA[manni66]]></dc:creator><pubDate>Wed, 19 Oct 2016 12:29:40 GMT</pubDate></item><item><title><![CDATA[Reply to C2027 in Struct on Wed, 19 Oct 2016 17:33:00 GMT]]></title><description><![CDATA[<p>Ich glaube Cjeans hat überhaupt keine Ahnung vom programmieren .</p>
<p>Dieses Forum erwartet sehr viel eigenleistung <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f576.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--sunglasses"
      title=":sunglasses:"
      alt="🕶"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2512156</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2512156</guid><dc:creator><![CDATA[Helfer]]></dc:creator><pubDate>Wed, 19 Oct 2016 17:33:00 GMT</pubDate></item></channel></rss>