Constructor Vtable Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn
Undefined Reference To Vtable For Constructor
more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags undefined reference to vtable for constructor and destructor Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you,
Vtable Error C++
helping each other. Join them; it only takes a minute: Sign up undefined reference to vtable when calling constructor of base class up vote 0 down vote favorite I am working on a project for school and I undefined reference to vtable for destructor ran into a problem I am not sure how to solve. Here are bits of the code (not the whole classes) and the error message: class CCPU { public: CCPU ( uint8_t * memStart, uint32_t pageTableRoot ); virtual ~CCPU ( void ) { } virtual uint32_t GetMemLimit ( void ) const = 0; virtual bool SetMemLimit ( uint32_t pages ) = 0; virtual bool NewProcess ( void * processArg, void (* entryPoint) ( CCPU *, void undefined reference to vtable qt * ), bool copyMem ) = 0; bool ReadInt ( uint32_t address, uint32_t & value ); bool WriteInt ( uint32_t address, m_PageTableRoot; }; This is the class that inherits from the one above: class CProcManager : public CCPU { public: CProcManager( uint8_t* memStart,uint32_t pageTableRoot ) : CCPU(memStart, pageTableRoot) {} virtual uint32_t GetMemLimit ( void ) const; virtual bool SetMemLimit ( uint32_t pages ); virtual bool NewProcess ( void * processArg, void (* entryPoint) ( CCPU *, void * ), bool copyMem ); static void InitInfoPages (uint8_t * pages_mem); }; And this would be the code calling the constructor: CProcManager init_ccpu((uint8_t*)mem, 32/*just a test number*/); The error message I get: solution.o: In function `CProcManager::CProcManager(unsigned char*, unsigned int)': /home/Jan/OSY/OSY-2/solution.cpp:19: undefined reference to `vtable for CProcManager' solution.o: In function `CProcManager::~CProcManager()': /home/Jan/OSY/OSY-2/solution.cpp:15: undefined reference to `vtable for CProcManager' collect2: error: ld returned 1 exit status make: *** [test1] Error 1 All the methods of CCPU and CProcManager classes are defined and I am not supposed to change the CCPU class (this class was provided in the project assignment). Can someone please explain to me where the problem lies(I guess its something with definitions)? c++ inheritance methods constructor vtable share|improve this question edited Apr 21 '14 at 14:55 asked Apr 21 '14 at 10:54 user2898639 725 add a comment| 1 Answer 1 active oldest votes up vote 3 down vote accepted Thi
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more
Undefined Reference To Vtable For Class
about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges undefined reference to vtable for derived class Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each
Undefined Reference To Vtable For Constructor Qt
other. Join them; it only takes a minute: Sign up c++ undefined reference to `vtable up vote 2 down vote favorite My question has changed from the other one I have posted. I started out with multiple files and http://stackoverflow.com/questions/23195950/undefined-reference-to-vtable-when-calling-constructor-of-base-class decided to put it all in one main.cpp file for now just to get it working. main.cpp: #include
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 http://www.dreamincode.net/forums/topic/172722-undefined-reference-to-vtable/ (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
4
5
6
Reply 10 Replies - 11066 Views - Last Post: 09 May 2010 - 01:09 PM Rate Topic: #1 diego_pmc D.I.C Addict Reputation: 83 Posts: 565 Joined: 13-May 09 Undefined reference to vtable Posted 09 May 2010 - 03:51 AM Hi, I'm having an odd linker error that I don't know how to solve. It is telling me that there is an undefined reference to the vtable for EnState() and ~EndState() constructor and destructor. I've looked around the web and it seems this kind of error is related to classes inheriting from pure virtual classes (EndState inherits from GameState, which is pure virtual). Here's my project files (includes VS10 and PN projects): > http://www.mediafire.com/?mfjkmj5glct Does anyone know how I can fix this? INFO: EndState header: include\game_state\end_state.h EndState source: source\game_state\end_state.cpp GameState abstract class header: include\game_state\game_state.h GameState abstract class source: (no source) This post has been edited by diego_pmc: 09 May 2010 - 09:18 AM Is This A Good Question/Topic? 0 Back to top MultiQuote Quote + Reply Replies To: Undefined reference to vtable #2 sarmanu D.I.C Lover Reputation: 966 Posts: 2,362 Joined: 04-December 09 Re: Undefined reference to vtable Posted 09 May 2010 - 05:56 AM You may try to add a destructor in GameState class, and a constructor. That's because EndState inherits from this class. Of course you won't need them, but I don't think that you can compile otherwise: class GameState { public: GameState() { } // May be virtual too? Depends on what you try to do. ~GameState() { } virtual void onOpen() = 0; virtual void onClose() = 0; virtual void onEnter() = 0; virtual void onExit() = 0; virtual void update(GameManager*, UserController*) = 0; virtual void render(GraphicsRenderer*) = 0; }; #endif // GAME_STATE_H Try it. PS: To be honest, I didn't really follow your code, but that seems to be a problem though. This post has been edited by sarmanu: 09 May 2010 - 06:07 AM Was This Post Helpful? 0 Back to top MultiQuote Quote + Reply #3 joesyuh D.I.C Head Reput