I am working with classes and legacies and I found this first error in a much bigger program than the one I will present to you:
undefined reference to vtable for class xxx
Trying to recreate the error in a small program I found this error
[Error] invalid new-expression of abstract class type 'bebe'
[Note] because the following virtual functions are pure within 'bebe':
[Note] virtual double abuelo::expresion()
And I think it points in the same direction. I know it has to do with the fact that the grandfather class is a pure virtual class, but I do not understand exactly what I should do, if I stop doing it pure, if I implement the pure function in each function, if I make virtual the children, if do static cast, or if you just do not call the grandpa class. On the site in English I found similar questions but the concepts In English they make me quite confused, for which I present the code:
#include <cctype>
#include <iostream>
#include <list>
#include <string>
using namespace std;
// clase abuelo es Virtual pura
class abuelo
{
public:
virtual double expresion() = 0;
};
// El resto de clases derivadas
class padre: public abuelo
{
public:
padre(abuelo *paterno, abuelo *materno);
static abuelo *foo();
private:
abuelo *paterno;
abuelo *materno;
};
abuelo *padre::foo()
{
return 0;
}
class madre: public abuelo
{
public:
static abuelo *foo();
};
class bebe: public madre
{
public:
bebe(string nombre)
{
this->nombre = nombre;
}
protected:
string nombre;
};
class hijo: public madre
{
public:
hijo(double value)
{
this->value = value;
}
double expresion()
{
return value;
}
private:
double value;
};
// LA funcion problematica
abuelo *madre::foo()
{
char paren;
double value;
cin >> ws;
if (isdigit(cin.peek()))
{
cin >> value;
//aquí quise declarar a hijo como new hijo pero me dijo que no
//reconocía a hijo
abuelo *hijo;// = new hijo(value);
return hijo;
}
if (cin.peek() == '(')
{
cin >> paren;
return padre::foo();
}
else
/* y aqui esta el error que les comento */
return new bebe("Luis");
return 0;
}
int main()
{
return 0;
}
I appreciate any light that you may throw on this problem. Thanks.