-2

I've searched through the many unresolved external symbol (lnk2019) problems on the SO and most of them were problems where someone forgot to put a constructor definition in a .cpp file or some .cpp file was not included in the building problem.

The Linker gives me some errors saying i have an unresolved external:

//error was on NotationInstrument.obj
iNotationInstrument<class Notation::NotationTrack>::~iNotationInstrument<class
Notation::NotationTrack>

(I also got some LNK2001 erros as well. It is another 'unresolved external symbol' error)

Yet this destructor IS defined. Since it's the destructor of an interface, the derived class (NotationInstrument) have a destructor that overrides the base's destructor. And NotationInstrument destructor is 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 the following just to be sure (for now, while debuggin)
#include "iNotationInstrument.h"
#include "iNotationTrack.h"
#include "NotationTrack.h"

namespace Notation
{

    NotationInstrument::NotationInstrument(){}
    NotationInstrument::~NotationInstrument(){}; //here is the 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 SO questions about linker erros, i've checked to make sure all the related files are included in the build.

(I didn't posted NotationTrack.h/.cpp and iNotationTrack.h to keep the question to a minimum. But i can post them if you want.)

Question: If ~NotationInstrument() overrides ~iNotationInstrument() and it's declared and defined, why i'm getting this linker error?

Edit about this beeing a duplicate: I've already read more than 20 posts about this unresolved external error on SO. But still i can't understand why i'm getting an unresolved external for something that i think is defined. I know i'm wrong because i'm getting this erros. I just can't find why. I tried Matthew James Briggs's answer, but i get the same errors.

Henri Augusto
  • 309
  • 3
  • 14
  • 1
    For those of us that haven't memorized the Visual Studio build error codes, what is `LNK2019`? Please edit your question to include the actual errors, complete, in full and unedited. – Some programmer dude Mar 07 '16 at 03:56
  • 1
    Also, destructors doesn't *override* each other. If you declare a virtual destructor in a base-class, you actually need to have it defined, even if it does nothing. – Some programmer dude Mar 07 '16 at 03:57
  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Ken White Mar 07 '16 at 04:00
  • @JoachimPileborg: LNK2019 is *unresolved external*. There's a canonical question regarding the topic [here](http://stackoverflow.com/q/12573816/62576) – Ken White Mar 07 '16 at 04:01
  • Thanks for pointing that out, but I've already read that, but for no help, as i said in the *Edit about this beeing a duplicate* section. – Henri Augusto Mar 07 '16 at 04:07
  • um, `class iNotationInstrument` is defined in a `.cpp` file. What is in `iNotationInstrument.h` ?? The `NotationInstrument.cpp` should not compile without being able to see that definition. – M.M Mar 07 '16 at 04:18
  • @HenriAugusto The first example in [this answer](http://stackoverflow.com/a/12574407/1505939) to the duplicate thread describes your situation exactly. If you look closely at the error message you posted, you will see that it is talking about `~iNotationInstrument`, and not `NotationInstrument` as you seem to have read it (based on the location of your comment `//here is the destructor`) – M.M Mar 07 '16 at 04:21
  • Although I agree that closing threads as duplicate of that megathread is unproductive , since it is difficult for newbie to identify their situation from the list of dozens of different situations – M.M Mar 07 '16 at 04:24
  • You're right. It was right behind my nose. It just wasn't clear that the code he posted was actually going to cause an error. I may have assumed it was actually correct. Maybe i just need to get some sleep. Thanks for pointing it. – Henri Augusto Mar 07 '16 at 04:30

2 Answers2

1

I think the problem is here

virtual ~iNotationInstrument() =0 ;

You cannot have a pure virtual destructor. Change this to

virtual ~iNotationInstrument() {}

Which defines the destructor inline.

Edit: I guess, you can have a pure virtual destructor, but you must define it.

Matthew James Briggs
  • 2,085
  • 2
  • 28
  • 58
0

Neither of these are right, just default it:

virtual ~iNotationInstrument() = default;
Vinnie Falco
  • 5,173
  • 28
  • 43