<?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[static class problem]]></title><description><![CDATA[<p>Hy,<br />
Ich möchte eine Klasse A innerhalb einer Klasse B als static nutzen.<br />
Der code:</p>
<pre><code>class A
{
public:
   void fooA()
   {
       cout &lt;&lt; &quot;test&quot; &lt;&lt; endl; 
   }
};

class B
{
private:
  static A a;
public:
  static void fooB()
  {
    B::a.fooA();
  }
};
</code></pre>
<p>ok...nochmal bearbeitet, aber Fehler nicht verschwunden!!!</p>
<p>Angepasst und noch nicht lauffähig... kann man das vielleicht umgehen?<br />
Also aus einer Klasse mit static Methoden möchte ich eine Klasse für alle nutzbar machen. Mir würde sonst noch Singleton einfallen, dann aber mit dem Nachteil das ich die Instanz überall gleich habe.</p>
<p>Fehler LNK2001 nicht aufgelöstes externes symbol &quot;&quot; private: static class A B::a&quot;<br />
Fehler LNK1120 nicht aufgelöste externe verweise<br />
Ich nutze Visual Studio VC++ Win32 Konsole</p>
<p>Danke</p>
<p>LÖSUNG:</p>
<pre><code>HEADER A:
class A
{
public:
   void fooA()
   {
       cout &lt;&lt; &quot;test&quot; &lt;&lt; endl; 
   }
};

HEADER B:
class B
{
private:
  static A a;
public:
  static void fooB(void);
};

SOURCE B:
A B::a;
void B::fooB()
{
  B::a.fooA();
}
</code></pre>
<p>Danke an alle für die Lösung</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/297410/static-class-problem</link><generator>RSS for Node</generator><lastBuildDate>Fri, 14 Aug 2026 11:40:31 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/297410.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 27 Dec 2011 19:01:01 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to static class problem on Wed, 28 Dec 2011 13:09:20 GMT]]></title><description><![CDATA[<p>Hy,<br />
Ich möchte eine Klasse A innerhalb einer Klasse B als static nutzen.<br />
Der code:</p>
<pre><code>class A
{
public:
   void fooA()
   {
       cout &lt;&lt; &quot;test&quot; &lt;&lt; endl; 
   }
};

class B
{
private:
  static A a;
public:
  static void fooB()
  {
    B::a.fooA();
  }
};
</code></pre>
<p>ok...nochmal bearbeitet, aber Fehler nicht verschwunden!!!</p>
<p>Angepasst und noch nicht lauffähig... kann man das vielleicht umgehen?<br />
Also aus einer Klasse mit static Methoden möchte ich eine Klasse für alle nutzbar machen. Mir würde sonst noch Singleton einfallen, dann aber mit dem Nachteil das ich die Instanz überall gleich habe.</p>
<p>Fehler LNK2001 nicht aufgelöstes externes symbol &quot;&quot; private: static class A B::a&quot;<br />
Fehler LNK1120 nicht aufgelöste externe verweise<br />
Ich nutze Visual Studio VC++ Win32 Konsole</p>
<p>Danke</p>
<p>LÖSUNG:</p>
<pre><code>HEADER A:
class A
{
public:
   void fooA()
   {
       cout &lt;&lt; &quot;test&quot; &lt;&lt; endl; 
   }
};

HEADER B:
class B
{
private:
  static A a;
public:
  static void fooB(void);
};

SOURCE B:
A B::a;
void B::fooB()
{
  B::a.fooA();
}
</code></pre>
<p>Danke an alle für die Lösung</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2161348</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2161348</guid><dc:creator><![CDATA[Ynnad]]></dc:creator><pubDate>Wed, 28 Dec 2011 13:09:20 GMT</pubDate></item><item><title><![CDATA[Reply to static class problem on Tue, 27 Dec 2011 19:07:26 GMT]]></title><description><![CDATA[<p>fooA() ist private Kann also nicht von B aufgerufen werden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2161350</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2161350</guid><dc:creator><![CDATA[Martin Kalbfuß]]></dc:creator><pubDate>Tue, 27 Dec 2011 19:07:26 GMT</pubDate></item><item><title><![CDATA[Reply to static class problem on Tue, 27 Dec 2011 19:20:52 GMT]]></title><description><![CDATA[<p>Du musst die Variable noch definieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2161352</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2161352</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Tue, 27 Dec 2011 19:20:52 GMT</pubDate></item><item><title><![CDATA[Reply to static class problem on Tue, 27 Dec 2011 22:47:08 GMT]]></title><description><![CDATA[<p><strong>void fooA();</strong> &lt;-- das ist nur ein Versprechen an den Compiler, dass du irgendwo eine entsprechende Funktion machst. Hast du aber in dem Code nicht, daher meckert er nun mit dir.<br />
Probier mal <strong>void fooA(){};</strong></p>
<pre><code>class A
{
public:
   void fooA(){};
}

class B
{
private:
  static A a;
public:
  static void fooB()
  {
    B::a.fooA();
  }
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2161409</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2161409</guid><dc:creator><![CDATA[Osbios]]></dc:creator><pubDate>Tue, 27 Dec 2011 22:47:08 GMT</pubDate></item><item><title><![CDATA[Reply to static class problem on Tue, 27 Dec 2011 22:58:40 GMT]]></title><description><![CDATA[<p>Muss ne class nicht mitn Semikolon beendet werden?</p>
<p>class foo<br />
{<br />
};</p>
<p>du hast es so:</p>
<p>class foo<br />
{<br />
} //kein Semikolon</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2161412</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2161412</guid><dc:creator><![CDATA[virtual user]]></dc:creator><pubDate>Tue, 27 Dec 2011 22:58:40 GMT</pubDate></item><item><title><![CDATA[Reply to static class problem on Wed, 28 Dec 2011 10:58:57 GMT]]></title><description><![CDATA[<p>So wie PI schon geschrieben hat, es fehlt noch die Definition der Variablen (in der Source-Datei, NICHT im Header - wegen der One Definition Rule (ODR)):</p>
<pre><code class="language-cpp">A B::a;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2161481</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2161481</guid><dc:creator><![CDATA[Th69]]></dc:creator><pubDate>Wed, 28 Dec 2011 10:58:57 GMT</pubDate></item></channel></rss>