<?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[Globale Konstante, in mehereren CppDateien]]></title><description><![CDATA[<p>Hallo ich habe eine Konstate cX, die in einer Header Datei TTT.h definiert wurde, diese wird nun in zahlreiche andere Cpp-Files inkludiert...</p>
<p>Mein Linker meckert jetzt, das cX (also die Konstante) bereits definiert ist...</p>
<p>habt ihr dazu ne Lösung... ?</p>
<p>Hab auch probiert da einfach 'extern' vorzusetzen, aber das hat auch nich gefunzt...</p>
<p>PS: cX ist etwa so definiert:</p>
<pre><code class="language-cpp">// TTT.h:
extern const char *cX[] = 
{
   &quot;Vielen&quot;,
   &quot;Dank&quot;,
   &quot;schonmal&quot;,
   &quot;!!!!!!&quot;
 // uvm.
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/150334/globale-konstante-in-mehereren-cppdateien</link><generator>RSS for Node</generator><lastBuildDate>Sat, 05 Sep 2026 14:32:42 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/150334.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 15 Jun 2006 13:23:53 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Globale Konstante, in mehereren CppDateien on Thu, 15 Jun 2006 13:23:53 GMT]]></title><description><![CDATA[<p>Hallo ich habe eine Konstate cX, die in einer Header Datei TTT.h definiert wurde, diese wird nun in zahlreiche andere Cpp-Files inkludiert...</p>
<p>Mein Linker meckert jetzt, das cX (also die Konstante) bereits definiert ist...</p>
<p>habt ihr dazu ne Lösung... ?</p>
<p>Hab auch probiert da einfach 'extern' vorzusetzen, aber das hat auch nich gefunzt...</p>
<p>PS: cX ist etwa so definiert:</p>
<pre><code class="language-cpp">// TTT.h:
extern const char *cX[] = 
{
   &quot;Vielen&quot;,
   &quot;Dank&quot;,
   &quot;schonmal&quot;,
   &quot;!!!!!!&quot;
 // uvm.
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1078171</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1078171</guid><dc:creator><![CDATA[GlobalRenderer]]></dc:creator><pubDate>Thu, 15 Jun 2006 13:23:53 GMT</pubDate></item><item><title><![CDATA[Reply to Globale Konstante, in mehereren CppDateien on Thu, 15 Jun 2006 13:39:16 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>das extern ist schon richtig.<br />
Nur darfst du in dem header die Variable nur dekalrieren, die Implementation und die Initialiation muß in die Imp-Datei</p>
<pre><code class="language-cpp">// TTT.h:
extern const char *cX[];

// TTT.cpp
const char *cX[] =
{
   &quot;Vielen&quot;,
   &quot;Dank&quot;,
   &quot;schonmal&quot;,
   &quot;!!!!!!&quot;
 // uvm.
}
</code></pre>
<p>bis bald<br />
akari</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1078183</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1078183</guid><dc:creator><![CDATA[akari]]></dc:creator><pubDate>Thu, 15 Jun 2006 13:39:16 GMT</pubDate></item><item><title><![CDATA[Reply to Globale Konstante, in mehereren CppDateien on Thu, 15 Jun 2006 13:41:11 GMT]]></title><description><![CDATA[<p>GlobalRenderer schrieb:</p>
<blockquote>
<p>Hallo ich habe eine Konstate cX, die in einer Header Datei TTT.h definiert wurde, diese wird nun in zahlreiche andere Cpp-Files inkludiert...</p>
<p>Mein Linker meckert jetzt, das cX (also die Konstante) bereits definiert ist...</p>
<p>Hab auch probiert da einfach 'extern' vorzusetzen, aber das hat auch nich gefunzt...</p>
</blockquote>
<p>Du hast die Definition der Variablen in der .h, Definitionen in .h-Dateien sind böse, weil jede .cpp die Definition übernimmt und der Linker meckert dann.<br />
Also: Niemals Code in Headerdateien packen.</p>
<p>Du brauchst eine Deklaration und das sieht wie folgt aus:</p>
<pre><code class="language-cpp">// TTT.h:

extern char const * cX[];    // Deklaration: extern + keine Zuweisung.

/// TTT.cpp
const char *cX[] =           // Definition: kein extern, Zuweisung möglich.
{
   &quot;Vielen&quot;,
   &quot;Dank&quot;,
   &quot;schonmal&quot;,
   &quot;!!!!!!&quot;
 // uvm.
}
</code></pre>
<p>[/quote]</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1078184</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1078184</guid><dc:creator><![CDATA[Xin]]></dc:creator><pubDate>Thu, 15 Jun 2006 13:41:11 GMT</pubDate></item><item><title><![CDATA[Reply to Globale Konstante, in mehereren CppDateien on Thu, 15 Jun 2006 13:47:30 GMT]]></title><description><![CDATA[<p>jo danke euch beiden...ich wusste das man das so trennen muss, war nur nicht sicher wegen der Konstante... :p dank nm</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1078189</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1078189</guid><dc:creator><![CDATA[GlobalRenderer]]></dc:creator><pubDate>Thu, 15 Jun 2006 13:47:30 GMT</pubDate></item></channel></rss>