ask for help to fix error in following code

Failure to build following code in VC2005. what is the wrong with the following code?
============================================================================

#include<cstdio>
using namespace std;
class Lock {
public:
Lock():isLooked(false) { }
bool AcquireLock() { return isLooked ? false : (isLooked=true);}
void ReleaseLock() {isLooked = false; }
private:
bool isLooked;
};
template <typename T>
class Singleton {
private:
static Lock lock;
static T* object;
protected:
Singleton() { };
public:
static T * Instance();
};
template <typename T>
T * Singleton<T>::Instance(){
if (object == 0) {
if(lock.AcquireLock()){
object = new T;
lock.ReleaseLock();
}
}
return object;
}
int main() {
int* singleton_foo = Singleton<int>::Instance();
return 0;
}

What errors are you getting?
link error.
A link error indicates that after the compilation stage, your linker cannot find an object file containing some compile code it needs. Generally this happens when you have neglected to add your libraries to the list of libraries to link against, or you have not compiled all your code. Does it state a function it cannot find?
Try to use newlines and spaces!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include<cstdio>
using namespace std;
class Lock {
public:
Lock():isLooked(false) { }
bool AcquireLock() { return isLooked ? false : (isLooked=true);}
void ReleaseLock() {isLooked = false; }
private:
bool isLooked;
};
template <typename T> 
class Singleton {
private:
static Lock lock;
static T* object;
protected:
Singleton() { };
public:
static T * Instance();
};

template <typename T>
Lock Singleton<T>::lock = Lock();

template <typename T>
T* Singleton<T>::object = 0;

template <typename T>
T * Singleton<T>::Instance(){
if (object == 0) {
if(lock.AcquireLock()){
object = new T;
lock.ReleaseLock();
}
}
return object;
}
int main() {
int* singleton_foo = Singleton<int>::Instance();
return 0;
}
Topic archived. No new replies allowed.