Curious "undefined reference to vtable"

My application was compiling just fine, until I needed to add a variable to one of the classes. The class is as follows:

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

#ifndef __VIEWPLANE__
#define __VIEWPLANE__

class Sampler;

class ViewPlane {
	public:
		int hres;
		int vres;
		int num_samples;
		int max_depth;
		float s;	//pixel_size
		float gamma;
		float inv_gamma;
		
		Sampler *sampler_ptr;
		
		ViewPlane(const int h = 50, const int v = 50, const int ns = 16, const int md = 1, const float _s = 1.0, const float g = 1.0, const float ig = 1.0);
		ViewPlane(const ViewPlane& vp);
		~ViewPlane(void);
		
		ViewPlane& operator =(const ViewPlane& vp);
		
		void set_sampler(Sampler* sp);
};

#endif 


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
33
34
35

#include "ViewPlane.h"
#include "Sampler.h"

ViewPlane::ViewPlane(const int h, const int v, const int ns, const int md, const float _s, const float g, const float ig) : hres(h), vres(v), num_samples(ns), max_depth(md), s(_s), gamma(g), inv_gamma(ig), sampler_ptr(NULL) {
}
 
ViewPlane::ViewPlane(const ViewPlane& vp) : hres(vp.hres), vres(vp.vres), num_samples(vp.num_samples), max_depth(vp.max_depth), s(vp.s), gamma(vp.gamma), inv_gamma(vp.inv_gamma), sampler_ptr(vp.sampler_ptr) {
}

ViewPlane::~ViewPlane(void) {
}

ViewPlane& ViewPlane::operator =(const ViewPlane& vp) {
	if (this == &vp) {
		return *this;
	}
	hres = vp.hres;
	vres = vp.vres;
	num_samples = vp.num_samples;
	max_depth = vp.max_depth;
	s = vp.s;
	gamma = vp.gamma;
	inv_gamma = vp.inv_gamma;
	return *this;
}

void ViewPlane::set_sampler(Sampler* sp) {
	if (sampler_ptr) {
		delete sampler_ptr;
		sampler_ptr = NULL;
	}
	num_samples = sp->get_num_samples();
	sampler_ptr = sp;
}


Apologies for the long code. The variable I added was max_depth. After I added this, I got the following compiler-errors:


main.o: In function `main':
main.cpp:(.text+0x8d): undefined reference to `vtable for App'
main.cpp:(.text+0x95): undefined reference to `vtable for App'
main.cpp:(.text+0xe1): undefined reference to `vtable for App'
main.cpp:(.text+0xe9): undefined reference to `vtable for App'
App.o: In function `App::App(QWidget*, QFlags<Qt::WindowType>)':
App.cpp:(.text+0xbe): undefined reference to `vtable for App'
App.o:App.cpp:(.text+0xc5): more undefined references to `vtable for App' follow
collect2: ld returned 1 exit status
make: *** [App] Error 1



I've always feared these error like nothing else, simply because they tell me absolutely nothing. I can say with 100% certainty that the error is not in main.cpp, the only changes that were made between working code and not-working code were the additions of the max_depth variable. Is it possible to see what's gone wrong here?

Thanks:)
max_depth has nothing to do with it, I'm sure.

"undefined reference" usually means you're trying to call a function, but you never gave that function a body. Though in this case, it's referring to the vtable for App.

To me, this suggests you are missing bodies for one or more virtual functions in your App class.

Can you post the App class? Or is it too large?

EDIT:

Or it's just not linking properly. Maybe try a clean and rebuild.
Last edited on
I should have mentioned that I already did several clean-rebuilds. I thought about what you said, and looked through more of the "newer" code in the project, and I found that another class was missing implementations for virtual functions, but the error was still there after I fixed it. Other than that, no code was added after the last successful build. Also, I should mention that the App class has not been edited since that either, so the error can't be in that class.
Wow, I solved it right after my last post! It turned out that for some reason Qt had created an extra file with the same name as another header file in the project. It is supposed to create a header file called "ui_foo.h" for every .ui file, but for some reason it had also created simply "foo.h" and filled it with the same thing. Removing this and cleaning-rebuilding fixed the issue! Thanks for your help :)
Topic archived. No new replies allowed.