0

I have MapListDialog which inherits from base class ListView. But I have problem with "undefined reference to" by MapListDialog constructor definition.

//create instance in main.cpp
mapListDialog = new MapListDialog(this);

Definition for MapListDialog inherited from ListView

src/modes/MapListDialog.h

#include <controls/ListView.h>

class MapListItem { 
public:
    const char *label; 
};

class MapListDialog : public ListView<MapListItem> {
public:
    //***compiler fails at line below ***
    MapListDialog(BaseView *parent): ListView<MapListItem>(parent) {};
    ~MapListDialog() {};    
};

Definition of ListView

src/controls/ListView.h

#include "Dialog.h"

template<class T>
class ListView : public Dialog {
public:
    ListView(BaseView *parent);
    ~ListView();
};

src/controls/ListView.cpp

#include "ListView.h"

template<class T>
ListView<T>::ListView(BaseView *parent):Dialog(parent) {}

template<class T>
ListView<T>::~ListView() { }

I think, is not necessary put here definition of Dialog, but for every case...

class Dialog : public BaseView {
    Dialog(BaseView *parent);
    ~Dialog();
}

class BaseView {
public:
    BaseView(BaseView *parent);
    ~BaseView();
}

MapListDialog.h:23: error: undefined reference to 'ListView::ListView(BaseView*)'

user1063364
  • 791
  • 6
  • 21
  • I'm suspecting you should read this: https://stackoverflow.com/a/495056/1387438 (you didn't describe how code is split in files, but definition of methods outside class declaration suggest that problem). – Marek R Sep 02 '19 at 12:33
  • 2
    ok so my guess was correct. Just move template to header file. – Marek R Sep 02 '19 at 12:40
  • 1
    Thank you, now it compiles correctly. I will read better posts above – user1063364 Sep 02 '19 at 12:43

0 Answers0