<?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[Frage zu static const]]></title><description><![CDATA[<p>Ich habe eine Klasse in der folgende Zeile steht</p>
<pre><code class="language-cpp">QueryPerformanceFrequency((LARGE_INTEGER*)&amp;QPC_Frequency);
</code></pre>
<p>Ich möchte QPC_Frequency als static const deklarieren, weil es keinen sinn machen würde für jede Instanz der Klasse QPC_Frequency neu anzulegen. Aber ich kann es ja nicht einfach in die .cpp schreiben wie gewohnt, weil QPC_Frequency ja übergeben wird. Wie sieht die syntax dafür aus?</p>
<p>Danke!</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/281621/frage-zu-static-const</link><generator>RSS for Node</generator><lastBuildDate>Sun, 23 Aug 2026 15:46:53 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/281621.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 04 Feb 2011 20:49:17 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Frage zu static const on Fri, 04 Feb 2011 20:49:17 GMT]]></title><description><![CDATA[<p>Ich habe eine Klasse in der folgende Zeile steht</p>
<pre><code class="language-cpp">QueryPerformanceFrequency((LARGE_INTEGER*)&amp;QPC_Frequency);
</code></pre>
<p>Ich möchte QPC_Frequency als static const deklarieren, weil es keinen sinn machen würde für jede Instanz der Klasse QPC_Frequency neu anzulegen. Aber ich kann es ja nicht einfach in die .cpp schreiben wie gewohnt, weil QPC_Frequency ja übergeben wird. Wie sieht die syntax dafür aus?</p>
<p>Danke!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2016776</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2016776</guid><dc:creator><![CDATA[Amino]]></dc:creator><pubDate>Fri, 04 Feb 2011 20:49:17 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu static const on Fri, 04 Feb 2011 21:41:18 GMT]]></title><description><![CDATA[<p>Wieso keine freie Methode (außerhalb der Klasse), dann hättest Du das Problem nicht.</p>
<p>Edit: Sorry, das ist totaler Blödsinn.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2016780</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2016780</guid><dc:creator><![CDATA[Eisflamme]]></dc:creator><pubDate>Fri, 04 Feb 2011 21:41:18 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu static const on Fri, 04 Feb 2011 21:17:19 GMT]]></title><description><![CDATA[<p>Ausserhalb der Klasse CTimer wird QPC_Frequency überhaupt nicht benötigt. Deshalb finde ich sollte es auch in der Klasse bleiben. Oder wie meinst du das?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2016788</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2016788</guid><dc:creator><![CDATA[Amino]]></dc:creator><pubDate>Fri, 04 Feb 2011 21:17:19 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu static const on Fri, 04 Feb 2011 21:50:17 GMT]]></title><description><![CDATA[<p>Naja, Du hast doch sicher eine CTimer.cpp und eine CTimer.h ?</p>
<p>In der CTimer.cpp steht dann einfach:</p>
<pre><code class="language-cpp">static const int QPC_Frequency = &lt;was auch immer&gt;;
</code></pre>
<p>Damit kann es in CTimer benutzt werden und keine andere Klasse kriegt es je zu sehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2016800</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2016800</guid><dc:creator><![CDATA[minastaros]]></dc:creator><pubDate>Fri, 04 Feb 2011 21:50:17 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu static const on Fri, 04 Feb 2011 21:53:09 GMT]]></title><description><![CDATA[<p>Ich sehe gerade das Problem nicht.</p>
<pre><code class="language-cpp">// Foo.hpp --------------------------------------------

#include &lt;windows.h&gt;

class Foo
{
// ...
    static LONGLONG const s_frequency;
};

// Foo.cpp --------------------------------------------

#include &quot;Foo.hpp&quot;
#include &lt;process.h&gt;

namespace { // anonymer namespace für die helper-funktion

LONGLONG GetPerformanceCounterFrequency()
{
    LARGE_INTEGER f;
    if (!::QueryPerformanceFrequency(&amp;f))
    {
        FehlerAusgeben();
        abort();
    }
    return f.QuadPart;
}

} // anonymer namespace Ende

LONGLONG Foo::s_frequency = GetPerformanceCounterFrequency();
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2016802</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2016802</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Fri, 04 Feb 2011 21:53:09 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu static const on Fri, 04 Feb 2011 22:05:12 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/21506">@minastaros</a>:</p>
<p>Ja, so geht es normalerweise. Ich hatte aber das Problem, dass ich den Wert erst aus einer Funktion holen muss.</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/13960">@Hustbaer</a>:</p>
<p>Danke, ich denke es ist das was ich gesucht habe.<br />
Ich wusste gar nicht, dass man Definitionen so beschränken kann, dass sie nur noch innerhalb einer Datei gefunden werden. Oder hab ich jetzt den Anonymen Namespace falsch verstanden?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2016808</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2016808</guid><dc:creator><![CDATA[Amino]]></dc:creator><pubDate>Fri, 04 Feb 2011 22:05:12 GMT</pubDate></item><item><title><![CDATA[Reply to Frage zu static const on Fri, 04 Feb 2011 22:44:59 GMT]]></title><description><![CDATA[<p>Nö, ich denke du hast das schon richtig verstanden.</p>
<p>Wobei IMO auch nix dagegen spricht, die GetPerformanceCounterFrequency öffentlich zu machen. Nicht als Teil der Counter-Klasse, sondern einfach als &quot;freistehende&quot; Hilfsfunktion - für wo auch immer sie gebraucht wird.</p>
<p>In der Arbeit verwenden wir eine eigene Library voll mit solchen Hilfsfunktionen (und Templates und Klassen). Man muss den Code ja nicht überall duplizieren wo man ihn braucht, auch wenn es &quot;nur Hilfsfunktionen&quot; sind.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2016820</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2016820</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Fri, 04 Feb 2011 22:44:59 GMT</pubDate></item></channel></rss>