My code is like this:
Basic.h
#define Type double
Model.h
#include "Basic.h"
class Model{
protected:
int _N;
public:
Model(int _N, Type* config){ config=new Type[N]; _N=N}
virtual Type compute();
}
class Model1: public Model{
protected:
int _Nr,_Nc;
public:
Model1(int Nr, int Nc, Type* config):Model(Nr*Nc,config){_Nr=Nr;_Nc=Nc;}
virtual Type compute();
}
class Model2: Public Model{
public:
Model2(int N,Type* config):Model(N,config){/*other unrelated codes*/}
virtual Type compute();
}
Model1.cpp
#include "Model.h"
Type Model1::compute(){
/*definition*/
}
Model2.cpp
#include "Model.h"
Type Model2::compute(){
/*definition*/
}
Method.h
#include "Model.h"
void Method(Model* sys);
Method.cpp
#include "Method.h"
void Method(Model* sys){
Type a=sys->compute();
/*code*/}
Main.cpp
#include "Method.h"
int main(int argc, char** argv){
Model* sys=new Model2();
Method(sys);
/*code*/
}
I can't find any problems but the compiler keeps complaining "error LNK2019: unresolved external symbol void __cdecl Method(class Model *) referenced in function _main".
I am so frustrated because I am a beginner of this and fail to find out the key. I don't know what can cause this: is it anything wrong in my #define? Or it is because different subclass have functions with the same name(seems it should be OK)? Or there is other bugs? I don't even know to add what tags to this question...
Can anyone help me to figure this out? Thanks a lot!
Thanks for suggestions and I have updated the questions to make sure all the constructors are contained.