Ich bin nur ein Anfänger, der versucht, C++ zu lernen. Ich versuche das folgende Problem zu lösen. Ich habe keine Ahnung, was das Problem verursacht.Wie würde ich eine Unterklasse aus dieser abstrakten Klasse erstellen? Vtable Error
Dies ist die abstrakte Klasse I mit zur Verfügung gestellt werde:
#ifndef __EXPR_H__
#define __EXPR_H__
#include <string>
class Expr {
public:
virtual int eval() const = 0;
virtual std::string prettyPrint() const = 0;
virtual ~Expr();
};
#endif
ich eine Unterklasse dieser Klasse zu erstellen versuchen, sieht meine .h-Datei wie diese
#ifndef __NUM_H__
#define __NUM_H__
#include <iostream>
#include "expr.h"
//class of lone expression
class Num:public Expr
{
private:
int operand;
public:
Num(int operand):operand(operand){}
int eval() const;
std::string prettyPrint() const;
~Num(){}
};
#endif
Während meiner Umsetzung Num Klasse sieht wie folgt aus: "num.cc"
#include "num.h"
#include <sstream>
std::string Num::prettyPrint()
{
std::stringstream convert;
convert << operand;
return convert.str();
}
int Num::eval()
{
return operand;
}
Ich bekomme immer den folgenden Fehler. Ich habe keine Ahnung, was das verursacht.
Undefined symbols for architecture x86_64:
"vtable for Num", referenced from:
Num::Num(int) in rpn-dc20fb.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
"vtable for Expr", referenced from:
Expr::Expr() in rpn-dc20fb.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)
Jede Hilfe wäre willkommen. Vielen Dank!