c++ - Undefined reference to `typeinfo for class' and undefined reference to `vtable for class' -


this question has answer here:

i'm dealing inheritance in c++. wanted write program addition , subtraction of 2 arrays. heres code:

#include <iostream> #include <cmath> #include <sstream> using namespace std;  class root {     protected :              int size;             double *array;      public :          virtual ~root() {}         virtual root* add(const root&) = 0;         virtual root* sub(const root&) = 0;         virtual istream& in(istream&, root&) = 0;          virtual int getsize() const = 0;         virtual void setsize(int);         virtual int getat(int) const = 0; };  class aa: public root {      public :          aa();         aa(int);         aa(const aa&);         root* add(const root& a);         root* sub(const root& a);         istream& in(istream&, root&){}         int getsize() const;         void setsize(int);         int getat(int) const; };  class bb: public root { public:     bb() { }     bb(const bb& b) { }     root* add(const root& a);     root* sub(const root& a);     istream& in(istream&, root&){}     int getsize() const{}     void setsize(int){}     int getat(int) const{} };  aa::aa() {     size = 0;     array = null; }  aa::aa(int nsize) {     size = nsize;     array = new double[size+1];     for(int i=0; i<size; i++)         array[i] = 0; }  root* aa::add(const root& a) {     (int i=0; i<a.getsize(); i++)         array[i] += a.getat(i);     return new aa(); }  root* aa::sub(const root& a) { }  int aa::getsize() const {     return size; }  void aa::setsize(int nsize) {     size = nsize;     array = new double[size+1];     for(int i=0; i<size; i++)         array[i] = 0; }  int aa::getat(int index) const {     return array[index]; }  root* bb::add(const root& a) {     return new bb(); }  root* bb::sub(const root& a) {  }  int main(int argc, char **argv) { } 

but have strange errors:

/home/brian/desktop/temp/untitled2.o||in function `root::~root()':| untitled2.cpp:(.text._zn4rootd2ev[_zn4rootd5ev]+0xb)||undefined reference `vtable root'| /home/brian/desktop/temp/untitled2.o||in function `root::root()':| untitled2.cpp:(.text._zn4rootc2ev[_zn4rootc5ev]+0x8)||undefined reference `vtable root'| /home/brian/desktop/temp/untitled2.o:(.rodata._zti2bb[typeinfo bb]+0x8)||undefined reference `typeinfo root'| /home/brian/desktop/temp/untitled2.o:(.rodata._zti2aa[typeinfo aa]+0x8)||undefined reference `typeinfo root'| ||=== build finished: 4 errors, 0 warnings ===| 

dont know came from, dont how 'fix' them. in advance;)

root::setsize isn't declared pure virtual, means must defined. presumably, should pure other functions:

virtual void setsize(int) = 0;                           ^^^ 

if you're interested in gory details of why particular error: compiler needs generate class's virtual/rtti metadata somewhere and, if class declares non-pure, non-inline virtual function, generate in same translation unit function's definition. since there no definition, don't generated, giving error.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -