c++ - Link error with a defined destructor -


i've searched through many unresolved external symbol (lnk2019) problems on , of them problems forgot put constructor definition in .cpp file or .cpp file not included in building problem.

the linker gives me errors saying have unresolved external:

//error on notationinstrument.obj inotationinstrument<class notation::notationtrack>::~inotationinstrument<class notation::notationtrack> 

(i got lnk2001 erros well. 'unresolved external symbol' error)

yet destructor defined. since it's destructor of interface, derived class (notationinstrument) have destructor overrides base's destructor. , notationinstrument destructor defined.

notationinstrument.h

#include "inotationinstrument.h" #include "notationtrack.h" #include <vector>  namespace notation {      class notationinstrument : public inotationinstrument<notationtrack>     {     public:         notationinstrument();         ~notationinstrument();          std::vector<notationtrack> gettracks() override ;     private:         std::vector<notationtrack> tracks;      }; // end of class "notationinstrument"  }; 

notationinstrument.cpp

#include "notationinstrument.h" //i've included following sure (for now, while debuggin) #include "inotationinstrument.h" #include "inotationtrack.h" #include "notationtrack.h"  namespace notation {      notationinstrument::notationinstrument(){}     notationinstrument::~notationinstrument(){}; //here destructor           std::vector<notationtrack> notationinstrument::gettracks()     {         return tracks;     };    }; 

inotationinstrument.cpp

#include <vector>  template <class notationtracktemplate> class inotationinstrument { public:     //inotationinstrument();     virtual ~inotationinstrument() =0 ; private:     virtual std::vector<notationtracktemplate> gettracks() =0 ;  }; 

following other questions linker erros, i've checked make sure related files included in build.

(i didn't posted notationtrack.h/.cpp , inotationtrack.h keep question minimum. can post them if want.)

question: if ~notationinstrument() overrides ~inotationinstrument() , it's declared , defined, why i'm getting linker error?

edit beeing duplicate: i've read more 20 posts unresolved external error on so. still can't understand why i'm getting unresolved external think defined. know i'm wrong because i'm getting erros. can't find why. tried matthew james briggs's answer, same errors.

i think problem here

virtual ~inotationinstrument() =0 ; 

you cannot have pure virtual destructor. change to

virtual ~inotationinstrument() {} 

which defines destructor inline.

edit: guess, can have pure virtual destructor, must define it.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -