Well, I was trying to fix this program, and I keep getting the errors :
Error 1 error LNK2019: unresolved external symbol “public: __thiscall ExcedeRangoInferior::ExcedeRangoInferior(void)” (??0ExcedeRangoInferior@@QAE@XZ) referenced in function _main
Error 2 error LNK2019: unresolved external symbol “public: __thiscall ExcedeRangoSuperior::ExcedeRangoSuperior(void)” (??0ExcedeRangoSuperior@@QAE@XZ) referenced in function _main
Here is the code:
The program asks for a value, and it throws an exception if the value exceeds a minimal or a maximal range
#include <iostream>
#include <exception>
class ExcepcionRango : public std::exception{
protected:
ExcepcionRango();
public:
virtual const char* lanzarExcepcion()=0;
};
class ExcedeRangoInferior : public ExcepcionRango{
public:
ExcedeRangoInferior();
const char* lanzarExcepcion() throw(){ //throw exception
return "Value out of minimal range";
}
};
class ExcedeRangoSuperior : public ExcepcionRango{
public:
ExcedeRangoSuperior();
const char* lanzarExcepcion() throw(){ //throw exception
return "value out of maximal range";
}
};
int obtainValue(int minimo, int maximo){ //obtain value
int valor; //value
std::cout<<"Introduce a value between "<<minimo<<" and "<<maximo<<" : "<<std::endl;
std::cin>>valor;
return valor;
};
int main(){
ExcedeRangoSuperior* exS = new ExcedeRangoSuperior();
ExcedeRangoInferior* exI= new ExcedeRangoInferior();
int min=3;
int max=10;
int valor=0; //value
try{
valor=obtainValue(min,max);
}catch(int){
if(valor<min){
exS->lanzarExcepcion();
}
if(valor>max){
exI->lanzarExcepcion();
}
}
delete exS;
delete exI;
std::cin.get();
}
PD:This was a homework, and its objective was to fix its errors, and get it running properly, and as I saw with the last thing I asked here, it seems that this code can show more errors, like syntax errors, maybe design and structural errors as well.
It looks like you’ve declared constructors for all of your exception types, but you haven’t defined those constructors anywhere. You’re getting linker errors saying that the constructor implementation isn’t being found. Try declaring these functions. For example:
Hope this helps!