static composition

Hello

I want to build a class autoCounter that counts the creations and destructions of objects and notify me if there is any object still alive.

I want to declare a static autoCounter in every class but i its givving errors of undefined reference of autoCounter's functions.
.h
1
2
3
4
class myClass{
static AutoCounter<myClass> counter;
static int something;
};

.cpp
1
2
int myClass::something = 0; //this works for int
//AutoCounter<myClass> myClass::counter;//this doesnt work. 


How can i explicitly call the constructor of a static object inside another class?

Thanks
What is the error message you get from AutoCounter<myClass> myClass::counter;?
These are the errors.
I include the autoCounter.h in the other header but still cant see it.
It looks like the object has never been created or somthing with the compilation order


1
2
3
4
5
6
/home/subuntu/programming/c++/cilkImageExceptions/image.cpp:20: undefined reference to `AutoCounter<IMAGE::Image>::increase()'
image.o: In function `~Image':
/home/subuntu/programming/c++/cilkImageExceptions/image.cpp:26: undefined reference to `AutoCounter<IMAGE::Image>::decrease()'
image.o: In function `__static_initialization_and_destruction_0':
/home/subuntu/programming/c++/cilkImageExceptions/image.cpp:15: undefined reference to `AutoCounter<IMAGE::Image>::AutoCounter()'
/home/subuntu/programming/c++/cilkImageExceptions/image.cpp:15: undefined reference to `AutoCounter<IMAGE::Image>::~AutoCounter()'

Ok i found the solution.
It was my mistake , i forgot that templates should be defined only in one header file without cpp
Topic archived. No new replies allowed.