c++ a missing vtable error

后端 未结 3 1791
盖世英雄少女心
盖世英雄少女心 2020-12-17 15:16

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 archi

相关标签:
3条回答
  • 2020-12-17 16:05

    Ah! Mulling over this I think I get what is happening. I'm betting that CCNode is code which belongs to somebody else.

    Any virtual functions you inherit are also virtual in the derived class... and it is common practice to make the destructor virtual... you might not realise the destructor is virtual.

    Also if you are using somebody else's header file, but forgot to link to their object file, it might cause this error, as the linker would be missing the destructor of CCNode.

    0 讨论(0)
  • 2020-12-17 16:08

    Try to add virtual destructor to your class. CCNode propably contains some virtual methods and your compiler failed cope with it.

        class MissionController: public CCNode
        {
    
          public:
             MissionController();
            virtual ~MissionController();
        };
    

    Is it some public framework, where can we see CCNode class definition? See vtable for .. referenced from compile error xcode or maybe http://www.parashift.com/c++-faq-lite/link-errs-missing-vtable.html for more help.

    0 讨论(0)
  • 2020-12-17 16:09

    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.

    0 讨论(0)
提交回复
热议问题