Monday, 1 May 2017

c++ - undefined reference to `vtable for class

I have take code from cppfaq 12.15 and trying to compile but getting error in linux with gcc version 4.8.4.





undefined reference to `vtable for




I am surprise as I do not have any virtual method. I have looked into following question but not able figure out issue.



c++ undefined reference to vtable



Undefined reference to 'vtable for xxx'




The code



#include
#include
#include using namespace std;

class Fred; typedef auto_ptr FredPtr;

class Fred {

public:
static FredPtr create() throw(bad_alloc);
static FredPtr create(int i) throw(bad_alloc);
static FredPtr create(const Fred& x) throw(bad_alloc);
virtual void goBowling();
private:
Fred(int i=10);
Fred(const Fred& x);
int i_;
};


FredPtr Fred::create() throw (bad_alloc) { return auto_ptr(new Fred()); }

FredPtr Fred::create(int i) throw(bad_alloc) {
return auto_ptr(new Fred(i)); }

FredPtr Fred::create(const Fred& x) throw(bad_alloc) {
return auto_ptr(new Fred(x)); }

Fred::Fred(int i) {

i_ = i;
cout<<" This is simple constructor"<
Fred::Fred(const Fred& x) {
i_ = x.i_;
cout<<" This is copy constrcutor"<
void sample() {
FredPtr p(Fred::create(5));
p->goBowling(); }


int main() {
sample();
return 0; }


Error:



/tmp/cc6JnLMO.o: In function `Fred::Fred(int)':
cpp12_15.cpp:(.text+0x204): undefined reference to `vtable for Fred'

/tmp/cc6JnLMO.o: In function `Fred::Fred(Fred const&)':
cpp12_15.cpp:(.text+0x247): undefined reference to `vtable for Fred'
collect2: error: ld returned 1 exit status

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...