Error Undefined Reference To Vtable For Constructor
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you undefined reference to vtable for destructor might have Meta Discuss the workings and policies of this
Undefined Reference To Vtable Qt
site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers
C++ Undefined Reference To Vtable For Class
or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community
Undefined Reference To Typeinfo For Constructor
of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up undefined reference to 'vtable for class' constructor [duplicate] up vote 22 down vote favorite 2 This question already has an answer here: c++ undefined reference to vtable 6 answers i am getting an undefined reference the vtable symbol may be undefined because the class is missing its key function to `vtable for student' while compiling the following header file: student.h class student { private: string names; string address; string type; protected: float marks; int credits; public: student(); student(string n,string a,string t,float m); ~student(); string getNames(); string getAddress(); string getType(); float getMarks(); virtual void calculateCredits(); int getCredits(); }; student::student(){} student::student(string n, string a,string t,float m) { names = n; address = a; marks = m; } student::~student(){} i can't find what is wrong in this.. c++ class constructor share|improve this question asked Apr 23 '14 at 21:11 Tarounen 1691212 marked as duplicate by Mooing Duck, Adriano Repetti, juanchopanza, Dave S, Kerrek SB Apr 23 '14 at 21:49 This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. add a comment| 1 Answer 1 active oldest votes up vote 42 down vote accepted You're declaring a virtual function and not defining it: virtual void calculateC
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings undefined reference to vtt and policies of this site About Us Learn more about Stack Overflow undefined reference to vtable for constructor qt the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation undefined reference to vtable for derived class Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it http://stackoverflow.com/questions/23255256/undefined-reference-to-vtable-for-class-constructor only takes a minute: Sign up Undefined reference to vtable up vote 122 down vote favorite 17 So, I'm getting the infamously horrible "undefined reference to 'vtable..." error for the following code (The class in question is CGameModule.) and I cannot for the life of me understand what the problem is. At first, I thought it was related to forgetting to http://stackoverflow.com/questions/3065154/undefined-reference-to-vtable give a virtual function a body, but as far as I understand, everything is all here. The inheritance chain is a little long, but here is the related source code. I'm not sure what other information I should provide. Note: The constructor is where this error is happening, it'd seem. My code: class CGameModule : public CDasherModule { public: CGameModule(Dasher::CEventHandler *pEventHandler, CSettingsStore *pSettingsStore, CDasherInterfaceBase *pInterface, ModuleID_t iID, const char *szName) : CDasherModule(pEventHandler, pSettingsStore, iID, 0, szName) { g_pLogger->Log("Inside game module constructor"); m_pInterface = pInterface; } virtual ~CGameModule() {}; std::string GetTypedTarget(); std::string GetUntypedTarget(); bool DecorateView(CDasherView *pView) { //g_pLogger->Log("Decorating the view"); return false; } void SetDasherModel(CDasherModel *pModel) { m_pModel = pModel; } virtual void HandleEvent(Dasher::CEvent *pEvent); private: CDasherNode *pLastTypedNode; CDasherNode *pNextTargetNode; std::string m_sTargetString; size_t m_stCurrentStringPos; CDasherModel *m_pModel; CDasherInterfaceBase *m_pInterface; }; Inherits from... class CDasherModule; typedef std::vector
on a plugin framework for an application, which will work by dynamically loading shared/dynamic libraries that http://www.cplusplus.com/forum/general/69623/ contain classes (unknown to the application) that derive from base classes (known to the application). I'm using MinGW with GCC and GNU-Make. The compiler output is below, including the rather strange linker error. g++ -DBUILDING_DLL -c -o plugin.o classes.cpp g++ -shared -o plugin.dll plugin.o plugin.o:classes.cpp:(.text$_ZN9baseClassC2Ev[baseClass::baseClass()]+0x8): undefined reference to `vtable for baseClass' collect2: undefined reference ld returned 1 exit status mingw32-make: *** [plugin.dll] Error 1 The problem appears to be in baseClass' constructor, which I haven't defined. I get the same error, but twice, if I define baseClass' constructor as 'baseClass() {}', as I did with derivedClass (see code). The code isn't too long, I'll post undefined reference to it below. Help is appreciated. I think I'm doing something wrong with constructors, but I'm not sure what. classes.h 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// classes.h #ifndef CLASSES_H #define CLASSES_H #ifdef BUILDING_DLL #define DLL_INTERFACE __declspec(dllexport) #else #define DLL_INTERFACE __declspec(dllimport) #endif class DLL_INTERFACE baseClass { public: virtual void testFunc(); }; class DLL_INTERFACE derivedClass : public baseClass { public: derivedClass() {}; ~derivedClass() {}; void testFunc(); private: void privateFunc(); }; #endif classes.cpp: 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// classes.cpp #include
2
3
4
5
6
7
8
9
CPP = g++ all: plugin.dll plugin.dll: plugin.o $(CPP) -shared -o $@ $? plugin.o: classes.cpp classes.h $(CPP) -DBUILDING_DLL -c -o $@ classes.cpp Apr 27, 2012 at 10:37pm UTC vlad from moscow (6539) I think the problem is that you did not define testFunc in the base class. Also you shall define destructor as virtual. Apr 27, 2012 at 10:50pm UTC codekiddy (783) Try this, 1
2
3