0

I am getting error NOTE: a missing vtable usually means the first non-inline virtual member function has no definition. "vtable for Algorithm2A". I suppose the problem in my base class I declared the function as pure virtual, and then in the header .h of derived class I redeclared it, in order to be able to implement it in the implementation file .cpp.

IAlgorithm2.h -- that is my abstract class

#include "IAlgorithm1.h"

//! Algorithm2 interface
class IAlgorithm2 {

public:

    ~IAlgorithm2() {
    }

    virtual std::vector<int> calculateLCP(std::string BWT)=0;
};

Now, I have the implementation of this in Algorithm2.h, andAlgorithm2.cpp.

Algorithm2A.hpp

class Algorithm2A : public IAlgorithm2 {

protected:
    IAlgorithm1 &algorithm1;

    std::vector<Interval> getIntervals(int i, int j) {
        return algorithm1.getIntervals(i, j);
    }

public:
    Algorithm2A(IAlgorithm1 &a) : algorithm1(a) {
    }

    std::vector<int> calculateLCP(std::string BWT);
};

Algorithm2A.cpp

#include "Algorithm2A.hpp"


std::vector<int> Algorithm2A::calculateLCP(std::string BWT) {
    // implementation of this
}

How should this be done? If I remove the definition from the Algorithm2A.h that it won't compile, and if I leave it there, than there is a vtable problem.

edit: this is not a matter of templates

IAlgorithm1.h

//! Algorithm1 interface
class IAlgorithm1 {

protected:
    virtual std::string uniqueCharsInInterval(int i, int j)=0;


public:

    ~IAlgorithm1() {
    }

    virtual std::vector<Interval> getIntervals(int i, int j)=0;
};

#endif /* Algorithm1_h */

Algorithm1A.h

#include "IAlgorithm1.h"

class Algorithm1A : public IAlgorithm1 {

protected:
    IRank &rank;
    OrderedAlphabet &alphabet;
    std::map<symbol_type, occurence_type> &C;
    std::string &BWT;

public:
        Algorithm1A(IRank &r,
                   OrderedAlphabet &a,
                   std::map<symbol_type, occurence_type> &c,
                   std::string &bwt):
                   rank(r), alphabet(a), C(c), BWT(bwt) {
        }

std::string uniqueCharsInInterval(int i, int j);

There is also an implementation file Algorithm1A.cpp

Whizzil
  • 1,264
  • 6
  • 22
  • 39
  • 1
    You do need to repeat the function declaration in `Algorithm2A`. What is the vtable problem? Any error messages? Note that the header file is called `Algorithm2A.h`, but you `#include `. Note the `pp` at the end. – BoBTFish Jan 09 '16 at 16:55
  • Undefined symbols for architecture x86_64: "Algorithm2A::~Algorithm2A()", referenced from: _main in main-ccca0a.o "vtable for Algorithm1A", referenced from: _main in main-ccca0a.o, and there is a NOTE. I will edit, and give also Algorithm1A code. – Whizzil Jan 09 '16 at 16:58
  • 1
    How are you building it? Looks like you haven't linked everything. – Alan Stokes Jan 09 '16 at 16:58
  • How should I be building it? I have several more files, and they include each others, so I think everything is linked. – Whizzil Jan 09 '16 at 17:05
  • You have declared the deconstructor ~Algorithm2A(); but you haven't implemented it. Maybe `virtual ~Algorithm2A() {};` is what you're looking for? – Vinícius Jan 09 '16 at 17:16
  • 1
    Having attempted to solve this, there seem to be myriad other problems. Please post a **[testcase](http://stackoverflow.com/help/mcve)** as instructed in the site rules. – Lightness Races in Orbit Jan 09 '16 at 17:33
  • `Algorithm1A` is hardly useful because it depends on other undisclosed parts of the code. Please build an [MCVE](http://stackoverflow.com/help/mcve). – n. m. could be an AI Jan 09 '16 at 17:45

1 Answers1

0

a missing vtable usually means the first non-inline virtual member function has no definition

The error message tells you what is wrong! The first non-inline virtual member function in IAlgorithm2 is not defined!

Since your first such function at present is calculateLCP, and you don't actually want to define it, the common fix is to give IAlgorithm2 a virtual destructor (which you should be doing anyway), with an empty definition.

You will also need to provide a definition for the Algorithm2A::~Algorithm2A that you have declared, or remove that declaration.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055