2012-06-15 4 views
1

글쎄, 난이 프로그램을 해결하기 위해 노력했다, 나는 오류가 계속 :C++ 예외/상속 오류 LNK2019

오류 1 오류 LNK2019 확인되지 않은 외부 기호를 (?? 0ExcedeRangoInferior @@ QAE @ XZ)

오류 2 오류 LNK2019 _main 함수에서 참조 : 확인되지 않은 외부 기호는 "공공 : __thiscall ExcedeRangoSuperior :: ExcedeRangoSuperior (무효)"(?? 0ExcedeRangoSuperior @@ QAE @ XZ)에서 참조 함수 _main

다음 코드는 다음과 같습니다. 프로그램에서 이것은 숙제, 그리고 그 목적은 그 오류를 수정하고 제대로 실행 얻을 수 있었고, 내가 같은 : 값이

#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 최소 또는 최대 범위를 초과하는 경우 값이, 그것은 예외를 throw 마지막으로 여기에서 물어 본 내용은이 코드가 구문 오류, 디자인 및 구조 오류와 같은 오류를 더 많이 표시 할 수있는 것으로 보입니다.

답변

1

모든 예외 유형에 대해 생성자가 선언 된 것처럼 보입니다. 그러나 어디에서나 해당 생성자를 정의하지 않았습니다. 생성자 구현을 찾을 수 없다는 링커 오류가 발생했습니다. 이러한 함수를 선언 해보십시오. 예 :

ExcedeRangoInferior::ExcedeRangoInferior() { 
    // Implement me! 
} 
ExcedeRangoSuperior::ExcedeRangoSuperior() { 
    // Implement me! 
} 

희망이 있습니다.

+0

예 감사합니다. 난 모든 생성자에서 방금 그것을 변경하고, 제대로 실행하지만, 지금, 값을 도입 후, 나는 어떤 예외도 : S는 어쩌면 내가 예외를 throw하는 함수를 선언하는 방식으로 오류가 발생하지 않습니다 – dlvx

+0

그건 별도의 질문입니다. 코드는 실제로 예외를 throw하지 않습니다 (여기서는 'throw'키워드가 없음). 도움을 요청하는 추가 답변을 올리려는 경우 전체 커뮤니티를 볼 수 있습니다. – templatetypedef