Was ist das Problem?Fehler Singleton in C++
#include <iostream>
using namespace std;
class Singleton
{
public:
void HelloWorld();
static Singleton* Instance(){
if (instanza == 0)
instanza = new Singleton ;
return instanza;
}
protected:
Singleton();
private:
static Singleton* instanza;
};
Singleton* Singleton:: instanza = 0;
void Singleton::HelloWorld()
{
cout << "Hello World!";
}
int main()
{
Singleton *p = Singleton ::Instance();
p->HelloWorld();
delete p;
}
g ++ -Wall -o "Singletons" "singleton.cpp" (im Ordner:/home/tarek/Desktop/New Codes) /tmp/ccL8BxOT.o: in der Funktion „Singleton :: Instanz () ":. singleton.cpp :(text._ZN9Singleton8InstanceEv [_ZN9Singleton8InstanceEv] + 0x24): undefined Verweis auf" Singleton :: Singleton() „ collect2: Fehler: ld ergab 1 Exit-Status Compilation fehlgeschlagen.
Zeigen Sie uns Inglese Fehler. Gerade 'LANG = C' vor dem g ++ Befehl. – Nidhoegger
Die Botschaft ist ziemlich klar: 'Singleton :: Singleton()' ist nicht definiert. – molbdnilo
* Was ist das Problem? * Ist das, was Sie berichten. Stackoverflow ist nicht Remote-Debugging-Dienst. Und Ihre Singleton Idiom ist gebrochen - was ist, wenn 'Instance' genannt wird before' = 0 'Instanz? Verwenden Sie lokale statische Variablen für Singletons. –