I have a class called SomeClass with a template
someclass.hpp
template<typename T>
SomeClass
{
public:
SomeClass(T& it, int a): t(it), b(a) {
CallMethod();
}
static void PrintSomething() {
std::cout << "static method in SomeClass" <<std::endl;
}
private:
T& t;
int b;
void CallMethod();
}
Methods are defined in someclass.cpp
void SomeClass<T>::Callmethod() {
t.SomeMethod();
}
Now, in main.cpp, I have,
T t;
t.SomeMethod(); //no error
SomeClass<T>::PrintSomething(); //call only this static method, it works
SomeClass<T> SomeClass(t, 2); //error
Errors are Undefined reference to all methods called inside the constructor. And undefined reference to destructor. This Only when I instantiate an object. No problems I call a static method from the class. I have included the object file in Make.
My makefile.
OBJECTS = \
src/main.o \
Src/someclass.o \
sys: $(OBJECTS)
$(CXX) $(CXXFLAGS) -o sys $(OBJECTS) $(LIB)
Any obvious errors? Help appreciated.