virtual - Reusing functions in C++ -
i having trouble writing code in class inherits class reuses function of class in 1 of functions
file pessoa.h:
#ifndef pessoa_h #define pessoa_h #include "data.h" #include <string> class pessoa { string nome; data aniversario; public: pessoa(string tnome, data taniversario){nome = tnome; aniversario = taniversario;} pessoa(){}; int aniversario(data data_atual); virtual void imprime(); ~pessoa(); }; #endif
file universitario.h:
#ifndef uni_h #define uni_h #include "pessoa.h" #include "data.h" class universitario: public pessoa { int matricula; data ingresso; public: universitario(int tmatricula, data tingresso, string nome, data aniversario): pessoa(nome, aniversario) {matricula = tmatricula; ingresso = tingresso;} universitario(){}; void imprime(); ~universitario(); }; #endif
function imprime() definition pessoa.cpp:
void pessoa::imprime() { cout << "nome: " << this->nome << endl; }
function imprime() definition uni.cpp:
void universitario::imprime() { this->imprime(); cout << "matricula: " << this->matricula << endl; ingresso.imprimed(); }
the error this:
undefined symbols architecture x86_64: "pessoa::~pessoa()", referenced from: universitario::~universitario() in main-0c1624.o universitario::universitario(int, data, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, data) in main-0c1624.o "typeinfo pessoa", referenced from: typeinfo universitario in main-0c1624.o "vtable pessoa", referenced from: pessoa::pessoa(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, data) in main- 0c1624.o note: missing vtable means first non-inline virtual member function has no definition. ld: symbol(s) not found architecture x86_64 clang: error: linker command failed exit code 1 (use -v see invocation)
i guessing error either on virtual or this.
"pessoa::~pessoa()", referenced from:
you need implement destructor. declared it.
instead of this:
~pessoa();
try this:
~pessoa() {}
same holds true universitario destructor.
Comments
Post a Comment