我从c++编译器得到一个奇怪的响应。我搜索了互联网,但没有发现有用或有帮助的东西。
编译器响应:
这些是代码文件:
main.cpp
#include <iostream>
#include "floating.hpp"
using namespace std;
int main(int argc, char* argv[])
{
return 0;
}
float.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
float.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){}
解决第一个问题非常感谢大家!
最佳答案
HexFloatingPoint
派生自FloatingPoint
,但您无需在FloatingPoint
的构造函数的初始化程序列表中调用任何HexFloatingPoint
的构造函数。这意味着将调用FloatingPoint
的默认(无参数)构造函数,但该类未定义它,因此会出现错误。
在FloatingPoint
的初始化程序列表中调用HexFloatingPoint
的构造函数,或者为FloatingPoint
提供默认的构造函数。
关于c++ - 没有匹配的函数来调用 “standard constructor”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14462617/