Headers problem

Hi,
I'm working on a strategy game. I had large "unit.cpp" and "unit.h" files with many classes in them and everything worked fine, but I felt that I should give each class its own .cpp and .h files. I did so and now it doesn't work.
I get
worker.obj : error LNK2019: unresolved external symbol "public: void __thiscall UNIT::StartBuilding<struct CENTER>(void)" (??$StartBuilding@UCENTER@@@UNIT@@QAEXXZ) referenced in function "public: virtual void __thiscall WORKER::Menu(char)" (?Menu@WORKER@@UAEXD@Z)


There is way too much code to post here, but the structure is something like this:
unit.h
1
2
3
4
5
struct UNIT{
    virtual void Menu(char)=0;
    template<typename T>
    void StartBuilding();
};

unit.cpp
1
2
3
4
5
#include "unit.h"
template<typename T>
void UNIT::StartBuilding(){
    do stuff
}

worker.h
1
2
3
4
5
#include "unit.h"
struct CENTER;
struct WORKER:public UNIT{
    void Menu(char);
};

worker.cpp
1
2
3
4
#include "worker.h"
void WORKER::Menu(char){
    StartBuilding<CENTER>();
}

CENTER is also derived from UNIT.
Non-template functions seem to work properly.

thanks for help
You should put the template function definition on the header and not on a separate source file
You must put the implementation of template functions and template classes in the header file; they cannot
(without difficulty) be in .cpp files.
Now I get
error C2027: use of undefined type 'CENTER'

As I understand including "center.h" in unit.h would only create more errors.
What can I do now?
Include center.h in worker.cpp.
Thank you all.
It works now.
Topic archived. No new replies allowed.