Wednesday, November 28, 2018

c++ - What does "vtable for *Class*" error means?




Moments ago i was coding some stuff... Everything went smoothly until the compiler gave me this error:



C:\Users\presgiovanni\workspace\verbaleesami\Debug/../persona.h:24: riferimento non definito a "vtable for Persona"
main.o: nella funzione "ZN7PersonaD2Ev":
C:\Users\presgiovanni\workspace\verbaleesami\Debug/../persona.h:25: riferimento non definito a "vtable for Persona"
collect2.exe: error: ld returned 1 exit status


(I'm sorry, but it's in italian, you know... It says "undefined reference to vtable for Persona")



This is the code of the header file interested (the lines are indicated with ">>"):



#ifndef PERSONA_H_
#define PERSONA_H_


#include
using std::cout;
using std::cin;
using std::endl;
using std::ostream;
using std::istream;

#include
using std::string;

class Persona{
public:
>> Persona(){;}
>> virtual ~Persona() = default;
virtual bool login(istream&);
virtual ostream& print(ostream&);
protected:
string nome, cognome, nickname, password;
};


#endif /* PERSONA_H_ */


Can someone explain me what happened (I'm working with Eclipse)? Thank you!


Answer



You failed to provide the definition of one of the member functions, specifically the one your compiler uses to chose the translation unit to store the vtable in.



With gcc, that would be the first non-inline member function.



Defining all member functions should solve the problem.


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...