0

Full Source code: https://github.com/amreo/gridb/tree/devel

I'm in trouble with my opensource library I've two class AbstractMapTile in src/abstractmaptile.h and MapTile in src/maptile.h

class AbstractMapTile : public virtual AbstractLocated, public QObject

and

class MapTile : public AbstractMapTile, public Located

I'm in trouble how to implement the destructor in MapTile and how to manage inheriting of MapTile and AbstractMapTile.

I've tried to put

virtual ~AbstractMapTile() = 0; 

in AbstractMapTile and

~MapTile() {}

in MapTile but I get these errors from linker:

g++ -m64 -Wl,-O1 -o test main.o moc_tests.o   -L/home/amreo/src/repo/gridb/gridb/test/../bin/ -lgridb -lQt5Test -lQt5Core -lpthread 
moc_tests.o: In function `MapTile::~MapTile()':
moc_tests.cpp:(.text._ZN7MapTileD1Ev[_ZN7MapTileD1Ev]+0x1a): undefined reference to `AbstractMapTile::~AbstractMapTile()'
moc_tests.o: In function `MapTile::~MapTile()':
moc_tests.cpp:(.text._ZN7MapTileD0Ev[_ZN7MapTileD0Ev]+0x1e): undefined reference to `AbstractMapTile::~AbstractMapTile()'
moc_tests.o: In function `Test::testMapTileCostructor1()':
moc_tests.cpp:(.text._ZN4Test22testMapTileCostructor1Ev[_ZN4Test22testMapTileCostructor1Ev]+0x1ee): undefined reference to `AbstractMapTile::~AbstractMapTile()'
moc_tests.o: In function `Test::testMapTileCostructor2()':
moc_tests.cpp:(.text._ZN4Test22testMapTileCostructor2Ev[_ZN4Test22testMapTileCostructor2Ev]+0x2e4): undefined reference to `AbstractMapTile::~AbstractMapTile()'
moc_tests.o: In function `Test::testMapTileCostructor3()':
moc_tests.cpp:(.text._ZN4Test22testMapTileCostructor3Ev[_ZN4Test22testMapTileCostructor3Ev]+0x2e8): undefined reference to `AbstractMapTile::~AbstractMapTile()'
moc_tests.o:moc_tests.cpp:(.text._ZN4Test22testMapTileCostructor3Ev[_ZN4Test22testMapTileCostructor3Ev]+0x37d): more undefined references to `AbstractMapTile::~AbstractMapTile()' follow

This is test code:

    AbstractMapTile* mapTile = new MapTile(10,20,nullptr);

    QCOMPARE(mapTile->x(), 10);
    QCOMPARE(mapTile->y(), 20);
    QVERIFY(mapTile->map() == nullptr);

    delete mapTile; 
amreo
  • 1
  • 2
  • 2
    You still need to implement the destructor: http://stackoverflow.com/questions/630950/pure-virtual-destructor-in-c – Unimportant Dec 31 '16 at 17:48
  • 1
    If your class is derived (also indirectly) from QObject, the first class in your derivation list needs to be a QObject derivated class. class AbstractMapTile : public QObject, public virtual AbstractLocated. This way the moc preprocessor will work ok. Not sure thow if this is your only issue. – Dragos Pop Dec 31 '16 at 17:50
  • 1
    If you really think a particular problem is Qt related, try an example without Qt to check your hypothesis. – juanchopanza Dec 31 '16 at 18:04
  • @DragosPop You should write that as an answer... – hyde Dec 31 '16 at 19:32

0 Answers0