0

Right I am getting weird linker errors which I've never seen before and which I can't really decipher.

Code for the RelationOwner and RelationUser can be found there. One remark: I've moved all function bodies to the source file instead of the header file. Naming has stayed the same.

Error   1   error LNK2019: unresolved external symbol "public: __thiscall RelationUser<class Family,class Citizen>::RelationUser<class Family,class Citizen>(class Family *)" (??0?$RelationUser@VFamily@@VCitizen@@@@QAE@PAVFamily@@@Z) referenced in function "public: __thiscall Citizen::Citizen(class Family &,class Name)" (??0Citizen@@QAE@AAVFamily@@VName@@@Z) *path*\Citizen.obj  CodeAITesting
Error   2   error LNK2019: unresolved external symbol "public: __thiscall RelationUser<class Family,class Citizen>::~RelationUser<class Family,class Citizen>(void)" (??1?$RelationUser@VFamily@@VCitizen@@@@QAE@XZ) referenced in function __unwindfunclet$??0Citizen@@QAE@AAVFamily@@VName@@@Z$1  *path*\Citizen.obj  CodeAITesting
Error   3   error LNK2019: unresolved external symbol "public: __thiscall RelationOwner<class Family,class Citizen>::~RelationOwner<class Family,class Citizen>(void)" (??1?$RelationOwner@VFamily@@VCitizen@@@@QAE@XZ) referenced in function __unwindfunclet$??0Family@@QAE@VName@@@Z$1   *path*\Family.obj   CodeAITesting

The first one is about a constructor and the second two are about the destructor. That I understand.

I've also implemented my own version of the User and Owner as the following:

// header of Family.h (Owner in the linked PDF file)
#include "Name.h"
#include "RelationOwner.h"

class Citizen;
class Family; // I didn't really know if this one was necessary.

class Family 
    : public RelationOwner<Family, Citizen>
{
public:
    Family(Name name);

private:
    Name name;
};

// Source of Family.cpp
#include "Name.h"

Family::Family(Name name)
    : name(name)
{
}

//Source of Citizen.h (User in the linked PDF)
#include "Name.h"
#include "RelationUser.h"

class Citizen;
class Family;

class Citizen 
    : public RelationUser<Family, Citizen>
{
public:
    Citizen(Family &family, Name name);

private:
    Name name;
};

// Source of Citizen.cpp
#include "Family.h"
#include "Name.h"
#include "RelationUser.h"

Citizen::Citizen(Family &family, Name name)
    : RelationUser<Family, Citizen>(&family),
    name(name)
{
}

As far as I know I am not doing anything fancypancy, yet it is complaining big time and I don't know why.

Daan Timmer
  • 14,771
  • 6
  • 34
  • 66
  • There is not enough information here for me to offer any suggestions. Usually the code for a template is in the header file. – brian beuning Mar 30 '14 at 16:17
  • Will try that. What other type of information would you need in order to offer suggestions? – Daan Timmer Mar 30 '14 at 16:18
  • The relation code is the key. Asking people to read a 10 page document is a little much. We don't even know if you copied the code from the document without changes. – brian beuning Mar 30 '14 at 16:21
  • Well I think you both have hit the spot. It indeed was the problem of of the template being split up in source and header files. Case closed I guess. – Daan Timmer Mar 30 '14 at 16:26

1 Answers1

0

Well as Brian Beuning told me "usually the code for a template is in the header file". And after reading n.m.'s linked possible duplicate I moved the implementation back to the header file and, it worked.

I guess that the duplicate question was spot on.

Daan Timmer
  • 14,771
  • 6
  • 34
  • 66