Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
714 views
in Technique[技术] by (71.8m points)

c++ a missing vtable error

I am getting a really weird error related to missing vtable for a given class constructor and destructor. Please help me to resolve this.

Undefined symbols for architecture i386:

  "vtable for A", referenced from:
      A::A() in A.o
      A::~MissionController() in A.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Code snippet;

.h file:

class A: public B

  public:
     A();
    ~A();

};

.cpp file..

 A::A()   
{


}

A::~A()
{


}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Found it,,trying with the sample, here is an exmaple.

class Shape{

public:
virtual int areas();
virtual void display();

virtual ~Shape(){};
};

The compiler complained

Undefined symbols for architecture x86_64:
"typeinfo for Shape", referenced from:
  typeinfo for trian in main_file.o
 "vtable for Shape", referenced from:
  Shape::Shape() in main_file.o
  NOTE: a missing vtable usually means the first non-inline virtual member      function has no definition.
   ld: symbol(s) not found for architecture x86_64
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  make: *** [cpp_tries] Error 1enter code here

The modification is empty or any inline content inside {} next to the virtual function

class Shape{

public:
    virtual int areas(){};
    virtual void display(){};

    virtual ~Shape(){};
};

Basically, its not finding the function definition for the non-inline virtual functions.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...