<?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[Union als rückgabewert]]></title><description><![CDATA[<p>Hi,</p>
<p>ich habe da mal eine Frage zu union.</p>
<p>Ich habe eine definiert</p>
<pre><code class="language-cpp">union IniRead
    {
        char *cTemp;
        bool bTemp;
        int iTemp;
    }uIniRead;
</code></pre>
<p>Diese will ich als rückgabewert haben denn meine Funktion</p>
<pre><code class="language-cpp">uIniRead __fastcall Translation::GetGlobalString(AnsiString Name, IniOption typ)
{
    uIniRead uTemp;

    TIniFile *ini = new TIniFile(GetAppDir() + LangDir + &quot;language.ini&quot;);

    switch(typ)
    {
        case ReadString:
            uTemp.cTemp = (char*)ini-&gt;ReadString(&quot;Translation&quot;, Name, &quot;StringNotFound&quot;);
            break;

        case ReadInteger:
        case ReadBool;
            uTemp.iTemp = ini-&gt;ReadInteger(&quot;Translation&quot;, Name, -1);
            break;
    }
    delete ini;

    return uTemp;
}
</code></pre>
<p>Soll eben entweder einen String, bool oder integer zurückgeben.</p>
<p>Ich bekomme allerdings die Fehler :</p>
<blockquote>
<p>[C++ Error] TRANSLATIONCLASS.H(56): E2303 Type name expected<br />
[C++ Error] TRANSLATIONCLASS.H(56): E2139 Declaration missing ;<br />
[C++ Warning] rev.h(3): W8058 Cannot create pre-compiled header: initialized data in header<br />
[C++ Error] translationclass.cpp(220): E2238 Multiple declaration for 'uIniRead'<br />
[C++ Error] defines.h(76): E2344 Earlier declaration of 'uIniRead'<br />
[C++ Error] translationclass.cpp(220): E2141 Declaration syntax error</p>
</blockquote>
<p>in der Klassendefinition<br />
Die ersten 2. Ich denke die letzten 3 sind folge Fehler denn ohne diese Funktion hats geklappt zu compilieren.</p>
<pre><code class="language-cpp">...
    uIniRead __fastcall GetGlobalString(AnsiString Name, IniOption);
...
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/113251/union-als-rückgabewert</link><generator>RSS for Node</generator><lastBuildDate>Wed, 22 Jul 2026 03:25:55 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/113251.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 21 Jun 2005 08:48:53 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Union als rückgabewert on Tue, 21 Jun 2005 08:48:53 GMT]]></title><description><![CDATA[<p>Hi,</p>
<p>ich habe da mal eine Frage zu union.</p>
<p>Ich habe eine definiert</p>
<pre><code class="language-cpp">union IniRead
    {
        char *cTemp;
        bool bTemp;
        int iTemp;
    }uIniRead;
</code></pre>
<p>Diese will ich als rückgabewert haben denn meine Funktion</p>
<pre><code class="language-cpp">uIniRead __fastcall Translation::GetGlobalString(AnsiString Name, IniOption typ)
{
    uIniRead uTemp;

    TIniFile *ini = new TIniFile(GetAppDir() + LangDir + &quot;language.ini&quot;);

    switch(typ)
    {
        case ReadString:
            uTemp.cTemp = (char*)ini-&gt;ReadString(&quot;Translation&quot;, Name, &quot;StringNotFound&quot;);
            break;

        case ReadInteger:
        case ReadBool;
            uTemp.iTemp = ini-&gt;ReadInteger(&quot;Translation&quot;, Name, -1);
            break;
    }
    delete ini;

    return uTemp;
}
</code></pre>
<p>Soll eben entweder einen String, bool oder integer zurückgeben.</p>
<p>Ich bekomme allerdings die Fehler :</p>
<blockquote>
<p>[C++ Error] TRANSLATIONCLASS.H(56): E2303 Type name expected<br />
[C++ Error] TRANSLATIONCLASS.H(56): E2139 Declaration missing ;<br />
[C++ Warning] rev.h(3): W8058 Cannot create pre-compiled header: initialized data in header<br />
[C++ Error] translationclass.cpp(220): E2238 Multiple declaration for 'uIniRead'<br />
[C++ Error] defines.h(76): E2344 Earlier declaration of 'uIniRead'<br />
[C++ Error] translationclass.cpp(220): E2141 Declaration syntax error</p>
</blockquote>
<p>in der Klassendefinition<br />
Die ersten 2. Ich denke die letzten 3 sind folge Fehler denn ohne diese Funktion hats geklappt zu compilieren.</p>
<pre><code class="language-cpp">...
    uIniRead __fastcall GetGlobalString(AnsiString Name, IniOption);
...
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/813807</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/813807</guid><dc:creator><![CDATA[Fox-Alpha]]></dc:creator><pubDate>Tue, 21 Jun 2005 08:48:53 GMT</pubDate></item><item><title><![CDATA[Reply to Union als rückgabewert on Tue, 21 Jun 2005 09:04:32 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>Deine Union heißt IniRead nicht uIniRead. Das ist schon eine Instanz auf IniRead. Lass das uIniRead bei der Deklaration deiner Union einfach weg.</p>
<p>Ciao</p>
]]></description><link>https://www.c-plusplus.net/forum/post/813829</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/813829</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Tue, 21 Jun 2005 09:04:32 GMT</pubDate></item><item><title><![CDATA[Reply to Union als rückgabewert on Tue, 21 Jun 2005 09:31:51 GMT]]></title><description><![CDATA[<p>Fox-Alpha schrieb:</p>
<blockquote>
<p>[cpp]<br />
case ReadString:<br />
<em><em>uTemp.cTemp = (char</em>)ini-&gt;ReadString(&quot;Translation&quot;, Name, &quot;StringNotFound&quot;);</em>*<br />
break;<br />
[/cpp]</p>
</blockquote>
<p>args... du weisst, dass <strong>ReadString</strong> einen AnsiString zurueckliefert, den du dann nach <strong>char</strong>* castest, beim verlassen der funktion wird der AnsiString freigegeben und dein <strong>cTemp</strong> zeigt in einen nicht definierten speicherbereich, was frueher oder spaeter zu einer zugriffsverletzung fuehrt!</p>
<p>reserviere mit <strong>new[]</strong> speicher fuer den string und kopiere ihn in <strong>cTemp</strong> hinein! daran denken ihn auch wieder frei zu geben!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/813856</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/813856</guid><dc:creator><![CDATA[Sunday]]></dc:creator><pubDate>Tue, 21 Jun 2005 09:31:51 GMT</pubDate></item></channel></rss>