I get a weird response from my c++ compiler. I searched the internet but came up with nothing usefull or helpfull...
Compiler Response:
First, the error. Your constructor for HexFloatingPoint
is not initialising the base class, FloatingPoint
. Since you have defined a constructor taking two arguments, and no default constructor (containing no arguments), derived classes must initialise it using the constructor you've defined:
HexFloatingPoint::HexFloatingPoint(int sign_length,int exp_length) :
FloatingPoint(sign_length, exp_length), // ADD THIS
significant_length(sign_length),
exponent_length(exp_length)
{}
Alternatively, you might want to be able to leave the base-class members uninitialised, or initialise them to default values, in which case you'll need to provide a default constructor:
FloatingPoint() {} // or initialise the members if you want
but this probably isn't what you want to do; you probably want to initialise them properly.
Secondly, the warning. Often when you have a polymorphic base class, you'll want to delete objects of the derived through a pointer to the base class. This is only allowed if the base class declares a virtual destructor; otherwise, such deletion gives undefined behaviour. I suggest you follow the compiler's advice and add one:
virtual ~FloatingPoint() {}
Finally, once you've fixed the compiler errors then (assuming there's no more code than what you posted) you'll get linker errors due to missing definitions of FloatingPoint::set_exponent
and FloatingPoint::print
. This is because you've declared them virtual but not pure, and haven't implemented them. They probably want to be pure virtual like set_significant
:
virtual void set_exponent(string number) = 0;
^^^