<?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[referencing class outside namespace]]></title><description><![CDATA[<p>hallo zusammen,</p>
<p>ich habe folgende codezeilen:</p>
<pre><code>#include &quot;mixim/modules/power/battery/SimpleBattery.h&quot;

namespace A {
    namespace B {

        class OmnetBatteryAccess : public ModuleAccess&lt;::SimpleBattery&gt; {

            OmnetBatteryAccess() : ModuleAccess&lt;::SimpleBattery&gt;(&quot;battery&quot;) {
            }

            virtual ::SimpleBattery* get() {
                cModule* p = findModuleSomewhereUp(&quot;battery&quot;, simulation.getContextModule());
                return dynamic_cast&lt;::SimpleBattery*&gt; (p);
            }

        };

    }
</code></pre>
<p>SimpleBattery liegt im globalen namespace, also hat keine namespace definition. Nun sagt der Compiler:</p>
<pre><code>In file included from common/system/battery/OmnetBattery.cc:9:0:
common/system/battery/OmnetBatteryAccess.h:18:57: error: ‘::SimpleBattery’ has not been declared
common/system/battery/OmnetBatteryAccess.h:18:57: error: ‘::SimpleBattery’ has not been declared
common/system/battery/OmnetBatteryAccess.h:18:55: error: ‘&lt;::’ cannot begin a template-argument list [-fpermissive]
common/system/battery/OmnetBatteryAccess.h:18:55: note: ‘&lt;:’ is an alternate spelling for ‘[’. Insert whitespace between ‘&lt;’ and ‘::’
common/system/battery/OmnetBatteryAccess.h:18:55: note: (if you use ‘-fpermissive’ G++ will accept your code)
common/system/battery/OmnetBatteryAccess.h:18:71: error: template argument 1 is invalid
common/system/battery/OmnetBatteryAccess.h:23:21: error: ‘SimpleBattery’ in namespace ‘::’ does not name a type
</code></pre>
<p>für die Zeile: public ModuleAccess&lt;::SimpleBattery&gt;</p>
<p>Ich dachte mit :: sage ich schon, dass SimpleBattery im globalen Namespace zu suchen ist. Wo ist den mein Fehler?</p>
<p>Gruß und Dank</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/325847/referencing-class-outside-namespace</link><generator>RSS for Node</generator><lastBuildDate>Sat, 11 Jul 2026 16:18:46 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/325847.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 20 May 2014 16:48:49 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to referencing class outside namespace on Tue, 20 May 2014 16:48:49 GMT]]></title><description><![CDATA[<p>hallo zusammen,</p>
<p>ich habe folgende codezeilen:</p>
<pre><code>#include &quot;mixim/modules/power/battery/SimpleBattery.h&quot;

namespace A {
    namespace B {

        class OmnetBatteryAccess : public ModuleAccess&lt;::SimpleBattery&gt; {

            OmnetBatteryAccess() : ModuleAccess&lt;::SimpleBattery&gt;(&quot;battery&quot;) {
            }

            virtual ::SimpleBattery* get() {
                cModule* p = findModuleSomewhereUp(&quot;battery&quot;, simulation.getContextModule());
                return dynamic_cast&lt;::SimpleBattery*&gt; (p);
            }

        };

    }
</code></pre>
<p>SimpleBattery liegt im globalen namespace, also hat keine namespace definition. Nun sagt der Compiler:</p>
<pre><code>In file included from common/system/battery/OmnetBattery.cc:9:0:
common/system/battery/OmnetBatteryAccess.h:18:57: error: ‘::SimpleBattery’ has not been declared
common/system/battery/OmnetBatteryAccess.h:18:57: error: ‘::SimpleBattery’ has not been declared
common/system/battery/OmnetBatteryAccess.h:18:55: error: ‘&lt;::’ cannot begin a template-argument list [-fpermissive]
common/system/battery/OmnetBatteryAccess.h:18:55: note: ‘&lt;:’ is an alternate spelling for ‘[’. Insert whitespace between ‘&lt;’ and ‘::’
common/system/battery/OmnetBatteryAccess.h:18:55: note: (if you use ‘-fpermissive’ G++ will accept your code)
common/system/battery/OmnetBatteryAccess.h:18:71: error: template argument 1 is invalid
common/system/battery/OmnetBatteryAccess.h:23:21: error: ‘SimpleBattery’ in namespace ‘::’ does not name a type
</code></pre>
<p>für die Zeile: public ModuleAccess&lt;::SimpleBattery&gt;</p>
<p>Ich dachte mit :: sage ich schon, dass SimpleBattery im globalen Namespace zu suchen ist. Wo ist den mein Fehler?</p>
<p>Gruß und Dank</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2400088</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2400088</guid><dc:creator><![CDATA[sven_]]></dc:creator><pubDate>Tue, 20 May 2014 16:48:49 GMT</pubDate></item><item><title><![CDATA[Reply to referencing class outside namespace on Tue, 20 May 2014 17:03:05 GMT]]></title><description><![CDATA[<blockquote>
<pre><code>common/system/battery/OmnetBatteryAccess.h:18:55: error: ‘&lt;::’ cannot begin a template-argument list [-fpermissive]
common/system/battery/OmnetBatteryAccess.h:18:55: note: ‘&lt;:’ is an alternate spelling for ‘[’. Insert whitespace between ‘&lt;’ and ‘::’
</code></pre>
</blockquote>
<p><s>Allerdings verstehe ich nicht, seit wann &lt;: eine Trigraph-Sequenz ist. Oder ist das etwas Implementierungsspezifisches?</s><br />
Nein, ist vom Standard garantiert - ist ein sog. alternative token, siehe die Tabelle in §2.6.</p>
<p>Daher muss da ein Leerzeichen zwischen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2400089</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2400089</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Tue, 20 May 2014 17:03:05 GMT</pubDate></item><item><title><![CDATA[Reply to referencing class outside namespace on Tue, 20 May 2014 17:02:01 GMT]]></title><description><![CDATA[<p>Arcoth schrieb:</p>
<blockquote>
<p>Allerdings verstehe ich nicht, seit wann &lt;: eine Trigraph-Sequenz ist.</p>
</blockquote>
<p>Seit es <strong>Di</strong>graph-Sequenzen gibt <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2400090</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2400090</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Tue, 20 May 2014 17:02:01 GMT</pubDate></item><item><title><![CDATA[Reply to referencing class outside namespace on Tue, 20 May 2014 17:03:05 GMT]]></title><description><![CDATA[<p>ne, ich habe keine trigraphe definiert. wie komme ich denn dann an die simple battery ran, wenn das im template ungültig ist. ich habe auch schon ein typedef probiert, mag er aber nicht. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2400091</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2400091</guid><dc:creator><![CDATA[sven_]]></dc:creator><pubDate>Tue, 20 May 2014 17:03:05 GMT</pubDate></item><item><title><![CDATA[Reply to referencing class outside namespace on Tue, 20 May 2014 17:05:40 GMT]]></title><description><![CDATA[<p>so, ändert auch nix:</p>
<pre><code>typedef ::SimpleBattery MiximBattery;

        class OmnetBatteryAccess : public ModuleAccess&lt; MiximBattery &gt; {
...
</code></pre>
<p>Endet mit:</p>
<pre><code>In file included from common/system/battery/OmnetBattery.cc:9:0:
common/system/battery/OmnetBatteryAccess.h:18:17: error: ‘SimpleBattery’ in namespace ‘::’ does not name a type
common/system/battery/OmnetBatteryAccess.h:20:57: error: ‘MiximBattery’ was not declared in this scope
common/system/battery/OmnetBatteryAccess.h:20:70: error: template argument 1 is invalid
common/system/battery/OmnetBatteryAccess.h:25:21: error: ‘MiximBattery’ does not name a type
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2400092</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2400092</guid><dc:creator><![CDATA[sven_]]></dc:creator><pubDate>Tue, 20 May 2014 17:05:40 GMT</pubDate></item><item><title><![CDATA[Reply to referencing class outside namespace on Tue, 20 May 2014 17:11:45 GMT]]></title><description><![CDATA[<p>ach, dumm. der fehler sitzt wie immer vor dem rechner. mein OmnetBatteryAccess wird von Battery aufgerufen mit Guard BATTERY_H, SimpleBattery.h setzt als Guard was? Genau, BATTERY_Y. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Ich danke für die Hilfe und entschuldige mich für die Blödheit. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2400094</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2400094</guid><dc:creator><![CDATA[sven_]]></dc:creator><pubDate>Tue, 20 May 2014 17:11:45 GMT</pubDate></item><item><title><![CDATA[Reply to referencing class outside namespace on Tue, 20 May 2014 17:12:23 GMT]]></title><description><![CDATA[<p>SeppJ schrieb:</p>
<blockquote>
<p>Arcoth schrieb:</p>
<blockquote>
<p>Allerdings verstehe ich nicht, seit wann &lt;: eine Trigraph-Sequenz ist.</p>
</blockquote>
<p>Seit es <strong>Di</strong>graph-Sequenzen gibt <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
</blockquote>
<p>Ja, die habe ich auch gerade im Standard gefunden. Habe mir fast gedacht, dass das der entsprechende Name ist. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<blockquote>
<p>ne, ich habe keine trigraphe definiert. wie komme ich denn dann an die simple battery ran, wenn das im template ungültig ist. ich habe auch schon ein typedef probiert, mag er aber nicht.</p>
</blockquote>
<p>Nein. Trigraph- bzw. Digraph-Sequenzen werden vom Standard vorgeschrieben. Laut Standard ist <code>&lt;:</code> im Code stets äquivalent zu <code>[</code> unabhängig davon wo es auftritt*.</p>
<ul>
<li>~Die Ausnahme ist das Stringizing im Präprozessor.~</li>
</ul>
<blockquote>
<p>Endet mit:<br />
[...]</p>
</blockquote>
<p>Dann wurde SimpleBattery nicht deklariert. Das ist eindeutig. Hast du die richtigen Header eingebunden, bist du vollkommen sicher dass <code>SimpleBattery</code> in diesem Header deklariert wird, ...?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2400095</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2400095</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Tue, 20 May 2014 17:12:23 GMT</pubDate></item><item><title><![CDATA[Reply to referencing class outside namespace on Tue, 20 May 2014 17:14:19 GMT]]></title><description><![CDATA[<p>hey arcoth,</p>
<p>viel über Tri- und Digraphe gelernt, und des Fehlers Lösung hab ich kurz vor dir gepostet. Dumm. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /> Danke vielmals für die Unterstützung.</p>
<p>Gruß</p>
<p>sven</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2400096</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2400096</guid><dc:creator><![CDATA[sven_]]></dc:creator><pubDate>Tue, 20 May 2014 17:14:19 GMT</pubDate></item></channel></rss>