2011-10-23 3 views
1
나는이 두 오류가 있어요

, 비주얼 스튜디오 2010의 전문이 C를 컴파일하는 동안 ++ 코드 :비주얼 스튜디오 2010 : C++ : 오류 LNK2001 : 확인되지 않은 외부 기호

Principal.obj : error LNK2001: unresolved external symbol "public: enum TP1::Couleur __thiscall TP1::Labyrinthe::trouveGagnant(void)" ([email protected]@[email protected]@[email protected]@XZ) 

Principal.obj : error LNK2001: unresolved external symbol "public: int __thiscall TP1::Labyrinthe::solutionner(enum TP1::Couleur)" ([email protected]@[email protected]@[email protected]@@Z) 

통화 당 모두와 .H 파일 다음과 같습니다 :

// principal.cpp 

\#include "Labyrinthe.h" 

using namespace std; 
using namespace TP1; 

int main() 
{ 
     try 
     { 
       Labyrinthe lab; 

       ifstream entree("FichiersLabyrinthe/rouge.txt"); 

       if (!entree) 
       { 
         cout << "Fichier rouge introuvable.\n"; 
         return 1; 
       } 

       lab.chargeLabyrinthe(Rouge, entree); 
       cout << "\nLabyrinthe rouge charg�.\n"; 
       entree.close(); 

       entree.open("FichiersLabyrinthe/vert.txt", ios::in); 
       if (!entree) 
       { 
         cout << "Fichier vert introuvable.\n"; 
         return 1; 
       } 

       lab.chargeLabyrinthe(Vert, entree); 
       cout << "\nLabyrinthe vert charg�.\n"; 
       entree.close(); 

       entree.open("FichiersLabyrinthe/bleu.txt", ios::in); 
       if (!entree) 
       { 
         cout << "Fichier bleu introuvable.\n"; 
         return 1; 
       } 

       lab.chargeLabyrinthe(Bleu, entree); 
       cout << "\nLabyrinthe bleu charg�.\n"; 
       entree.close(); 

       entree.open("FichiersLabyrinthe/jaune.txt", ios::in); 
       if (!entree) 
       { 
         cout << "Fichier jaune introuvable.\n\n"; 
         return 1; 
       } 

       lab.chargeLabyrinthe(Jaune, entree); 
       cout << "\nLabyrinthe jaune charg�.\n"; 
       entree.close(); 

       cout << "\nLe joueur rouge peut solutionner le labyrinthe en " 
           << lab.solutionner(Rouge) << " d�placements.\n"; 
       cout << "\nLe joueur vert peut solutionner le labyrinthe en " 
           << lab.solutionner(Vert) << " d�placements.\n"; 
       cout << "\nLe joueur bleu peut solutionner le labyrinthe en " 
           << lab.solutionner(Bleu) << " d�placements.\n"; 
       cout << "\nLe joueur jaune peut solutionner le labyrinthe en " 
           << lab.solutionner(Jaune) << " d�placements.\n"; 

       Couleur LeGagnant = lab.trouveGagnant(); 
       switch (LeGagnant) 
       { 
       case 0: 
         cout << endl << "Le joureur gagnant: Rouge" << endl << endl; 
         break; 
       case 1: 
         cout << endl << "Le joureur gagnant: Vert" << endl << endl; 
         break; 
       case 2: 
         cout << endl << "Le joureur gagnant: Bleu" << endl << endl; 
         break; 
       case 3: 
         cout << endl << "Le joureur gagnant: Jaune" << endl << endl; 
         break; 
       default: 
         cout << endl << "Le joureur gagnant: aucun!!" << endl << endl; 
         break; 
       } 
     } catch (exception & e) 
     { 
       cerr << e.what() << endl; 
     } 

     return 0; 
} 

// ====================================== ========== Labyrinthe.h

#ifndef LABYRINTHE_H_ 
#define LABYRINTHE_H_ 

#include <stdexcept> 
#include <iostream> 
#include <fstream> 
#include <sstream> 
#include <string> 

#include "Chemin.h" 
#include "Porte.h" 
#include "Piece.h" 
#include "FilePieces.h" 

#pragma warning(disable : 4290) 

namespace TP1 
{ 


class Labyrinthe 
{ 
public: 

     Labyrinthe(); 
     virtual ~Labyrinthe(); 
     Labyrinthe(const Labyrinthe&); 

     const Labyrinthe& operator =(const Labyrinthe& source) throw (std::bad_alloc); 

     void chargeLabyrinthe(Couleur couleur, std::ifstream &entree); 

     void ajoutePieceLabyrinthe(Piece &p) throw (std::bad_alloc); 

     int solutionner(Couleur joueur); 

     Couleur trouveGagnant(); 

     Chemin cheminLabyrinthe(Couleur joueur); 

private: 

     void ajoutePassage(Couleur couleur, int i1, int j1, int i2, int j2); 

     void placeDepart(std::string& nom) throw (std::logic_error); 

     void placeArrivee(std::string& nom) throw (std::logic_error); 


     class NoeudListePieces 
     public: 

       Piece piece; 

       NoeudListePieces *suivant; 
     }; 

     NoeudListePieces *trouvePiece(std::string &nom) const 
         throw (std::invalid_argument, std::logic_error); 
     NoeudListePieces *dernier; 

     Piece *depart, *arrivee; 

     int compteurLab; 

}; 

} 

#endif /* LABYRINTHE_H_ */ 

누구나 내가 도와 줄 수 있니? 감사.

답변

2

Labyrinthe::trouveGagnantLabyrinthe::solutionner 코드 정의가 제공되지 않았습니다. 컴파일러는 아무 곳에서나 정의되지 않은 두 가지 함수를 호출한다는 불평을하기 때문에 코드를 생성 할 수 없습니다.

Labyrinthe.cpp을 프로젝트에 포함시키는 것을 잊었습니까?

2

Labyrinthe.hprincipal.cpp에 대해서만 코드를 제공했습니다.

Labyrinthe.h에 선언 된 함수는 어디에도 정의되어 있지 않습니다. 대부분의 정의는 Labyrinthe.cpp에 있습니다. 해당 파일도 컴파일해야합니다.

일반적으로 컴파일러는 심볼 선언 만 찾습니다. 정의가 별도의 모듈에 상주 할 수 있기 때문입니다. 라이브러리와 링크 할 때 정의가 있습니다. 귀하의 경우에는 정의가 동일한 모듈에 있으므로 컴파일 할 구현 (cpp 파일의 일부)이 필요합니다.

관련 문제