我从我的 c++ 编译器得到一个奇怪的响应。我搜索了互联网,但没有找到任何有用或有帮助的...
编译器响应:
float.hpp|第 29 行|警告:`class HexFloatingPoint' 具有虚函数但非虚析构函数
在构造函数 `HexFloatingPoint::HexFloatingPoint(int, int)' 中:
float.cpp|第 5 行|错误:没有用于调用“FloatingPoint::FloatingPoint()”的匹配函数
float.hpp|第 16 行|注:候选对象是:FloatingPoint::FloatingPoint(const FloatingPoint&)
float.cpp|第 3 行|注:FloatingPoint::FloatingPoint(int, int)
这些是代码文件:
主文件
#include <iostream>
#include "floating.hpp"
using namespace std;
int main(int argc, char* argv[])
{
return 0;
}
浮动.hpp
#ifndef FLOATING
#define FLOATING
#include <string>
#include <vector>
using namespace std;
class FloatingPoint;
class HexFloatingPoint;
class HexDigit;
class HexDigitBool;
class HexDigitChar;
class FloatingPoint
{
private:
int significant_length;
int exponent_length;
public:
FloatingPoint(int sign_length,int exp_length);
virtual void set_significant(string number) = 0;
virtual void set_exponent(string number);
virtual void print();
};
class HexFloatingPoint : public FloatingPoint
{
private:
vector<HexDigit*> significant_length;
vector<HexDigit*> exponent_length;
public:
HexFloatingPoint(int sign_length,int exp_length);
void set_significant(string number);
void set_exponent(string number);
void print();
~HexFloatingPoint();
};
class HexDigit
{
public:
virtual void print()=0;
virtual void set_value(char c);
virtual int get_value();
};
class HexDigitBool : public HexDigit
{
private:
bool b[4];
public:
void print();
virtual void set_value(char c);
virtual int get_value();
};
class HexDigitChar : public HexDigit
{
private:
char c;
public:
void print();
virtual void set_value(char c);
virtual int get_value();
};
#endif
浮动.cpp
#include "floating.hpp"
FloatingPoint::FloatingPoint(int sign_length,int exp_length) : significant_length(sign_length),exponent_length(exp_length){}
HexFloatingPoint::HexFloatingPoint(int sign_length,int exp_length) : significant_length(sign_length),exponent_length(exp_length){}
void HexFloatingPoint::set_significant(string number){}
void HexFloatingPoint::set_exponent(string number){}
void HexFloatingPoint::print(){}
HexFloatingPoint::~HexFloatingPoint(){}
我希望你能帮助我。我已经尝试添加 FloatingPoint(); 在 floating.hpp 和 floating.cpp 但它没有帮助。
更新 1
将构造函数更改为
HexFloatingPoint::HexFloatingPoint(int sign_length,int exp_length) : FloatingPoint(sign_length,exp_length){}
编译器说不...
floating.o||In function `_ZNSt12_Vector_baseIP8HexDigitSaIS1_EED2Ev':|
stl_vector.h:(.text+0x8)||undefined reference to `vtable for FloatingPoint'|
floating.o||In function `_ZN13FloatingPointC1Eii':|
floating.cpp|3|undefined reference to `vtable for FloatingPoint'|'
更新 2
改变
class FloatingPoint
{
private:
int significant_length;
int exponent_length;
public:
FloatingPoint(int sign_length,int exp_length);
virtual void set_significant(string number) = 0;
virtual void set_exponent(string number);
virtual void print();
};
至
class FloatingPoint
{
private:
int significant_length;
int exponent_length;
public:
FloatingPoint(int sign_length,int exp_length);
virtual void set_significant(string number) = 0;
virtual void set_exponent(string number) = 0;
virtual void print() = 0;
};
解决了更新 1 中出现的错误
改变
class HexFloatingPoint : public FloatingPoint
{
private:
vector<HexDigit*> significant_length;
vector<HexDigit*> exponent_length;
public:
HexFloatingPoint(int sign_length,int exp_length);
void set_significant(string number);
void set_exponent(string number);
void print();
~HexFloatingPoint();
};
至
class HexFloatingPoint : public FloatingPoint
{
private:
vector<HexDigit*> significant_length;
vector<HexDigit*> exponent_length;
public:
HexFloatingPoint(int sign_length,int exp_length);
void set_significant(string number);
void set_exponent(string number);
void print();
virtual ~HexFloatingPoint();
};
已解决的警告
改变
HexFloatingPoint::HexFloatingPoint(int sign_length,int exp_length) : significant_length(sign_length),exponent_length(exp_length){}
至
HexFloatingPoint::HexFloatingPoint(int sign_length,int exp_length) : FloatingPoint(sign_length,exp_length),significant_length(sign_length),exponent_length(exp_length){}
修复了第一个问题
非常感谢各位!!