【发布时间】:2013-12-15 13:24:53
【问题描述】:
我使用 Eclipse+GCC+MinGW。
AbstractValue.h:
#ifndef ABSTRACTVALUE_H_
#define ABSTRACTVALUE_H_
#include <string>
class AbstractValue {
public:
virtual AbstractValue* add(AbstractValue*) = 0;
virtual AbstractValue* sub (AbstractValue*) = 0;
virtual AbstractValue* mul (AbstractValue*) = 0;
virtual AbstractValue* div (AbstractValue*) = 0;
virtual std::string toString () = 0;
virtual ~AbstractValue() = 0;
};
#endif /* ABSTRACTVALUE_H_ */
IntegerValue.h
#ifndef INTEGERVALUE_H_
#define INTEGERVALUE_H_
#include "../AbstractValue/AbstractValue.h"
#include <string>
class IntegerValue: public AbstractValue {
private:
int value;
public:
IntegerValue(int);
~IntegerValue();
int getValue();
IntegerValue* add (AbstractValue*);
IntegerValue* sub (AbstractValue*);
IntegerValue* mul (AbstractValue*);
IntegerValue* div (AbstractValue*);
std::string toString();
};
IntegerValue.cpp:
#include "IntegerValue.h"
#include <stdlib.h>
IntegerValue::IntegerValue(int a) : value(a) {};
IntegerValue::~IntegerValue() {}
int IntegerValue::getValue() {
return this -> value;
}
IntegerValue* IntegerValue::add (AbstractValue* another) {
IntegerValue* anotherInteger = (IntegerValue*) another;
int newValue = this -> getValue() + anotherInteger -> getValue();
return new IntegerValue(newValue);
}
IntegerValue* IntegerValue::sub (AbstractValue* another) {
IntegerValue* anotherInteger = (IntegerValue*) another;
int newValue = this -> getValue() - anotherInteger -> getValue();
return new IntegerValue(newValue);
}
IntegerValue* IntegerValue::mul (AbstractValue* another) {
IntegerValue* anotherInteger = (IntegerValue*) another;
int newValue = this -> getValue() * anotherInteger -> getValue();
return new IntegerValue(newValue);
}
IntegerValue* IntegerValue::div (AbstractValue* another) {
IntegerValue* anotherInteger = (IntegerValue*) another;
int newValue = this -> getValue() / anotherInteger -> getValue();
return new IntegerValue(newValue);
}
std::string IntegerValue::toString() {
char *res = new char[1000];
itoa(this -> value, res, 10);
std::string a (res);
delete[] res;
return a;
}
我在IntegerValue::~IntegerValue() {} 上收到undefined reference to AbstractValue::~AbstractValue()。为什么?
【问题讨论】: