我从我的C ++编译器一个奇怪的反应。 我在网上搜索,但什么也没有有用或有益想出了...
编译器响应:
floating.hpp |在线29 |警告:`类HexFloatingPoint”有虚函数,但非虚析构函数
在构造函数中`HexFloatingPoint :: HexFloatingPoint(INT,INT)“:
floating.cpp | 5号线|错误:调用`浮点::浮点不匹配功能()
floating.hpp | 16行|注:考生:浮点::浮点(const的浮点和)
floating.cpp |线路3 |注:浮点::浮点(INT,INT)
这些都是代码文件:
main.cpp中
#include <iostream>
#include "floating.hpp"
using namespace std;
int main(int argc, char* argv[])
{
return 0;
}
floating.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
floating.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(){}
我希望你能帮助我。 我已经尝试添加浮点(); 在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){}
固定的第一个问题
非常感谢球员!