S
sieg1974
Hi,
I know it must be a simple mistake, but I'm just learning C++ and can't
figure out what's wrong. Any help will be vey much appreciated
I got the following error messages when the following program is
compiled and linked. What could be wrong?
Thanks,
Andre
/tmp/ccX0Z0Il.o(.text+0x17d): In function `Singleton::Instance()':
: undefined reference to `Singleton::theSingleton'
/tmp/ccX0Z0Il.o(.text+0x1ca): In function `Singleton::Instance()':
: undefined reference to `Singleton::theSingleton'
/tmp/ccX0Z0Il.o(.text+0x1cf): In function `Singleton::Instance()':
: undefined reference to `Singleton::theSingleton'
collect2: ld returned 1 exit status
#include <iostream>
class Singleton
{
public:
static Singleton * Instance();
~Singleton();
private:
Singleton();
static Singleton * theSingleton;
};
Singleton::Singleton()
{
std::cout << "Singleton constructot\n";
}
Singleton::~Singleton()
{
std::cout << "Singleton destructor\n";
}
Singleton * Singleton::Instance()
{
if( !theSingleton )
{
theSingleton = new Singleton();
}
return( theSingleton );
}
Singleton * theSingleton = 0;
int main()
{
return( 0 );
}
I know it must be a simple mistake, but I'm just learning C++ and can't
figure out what's wrong. Any help will be vey much appreciated
I got the following error messages when the following program is
compiled and linked. What could be wrong?
Thanks,
Andre
/tmp/ccX0Z0Il.o(.text+0x17d): In function `Singleton::Instance()':
: undefined reference to `Singleton::theSingleton'
/tmp/ccX0Z0Il.o(.text+0x1ca): In function `Singleton::Instance()':
: undefined reference to `Singleton::theSingleton'
/tmp/ccX0Z0Il.o(.text+0x1cf): In function `Singleton::Instance()':
: undefined reference to `Singleton::theSingleton'
collect2: ld returned 1 exit status
#include <iostream>
class Singleton
{
public:
static Singleton * Instance();
~Singleton();
private:
Singleton();
static Singleton * theSingleton;
};
Singleton::Singleton()
{
std::cout << "Singleton constructot\n";
}
Singleton::~Singleton()
{
std::cout << "Singleton destructor\n";
}
Singleton * Singleton::Instance()
{
if( !theSingleton )
{
theSingleton = new Singleton();
}
return( theSingleton );
}
Singleton * theSingleton = 0;
int main()
{
return( 0 );
}