2013-11-17 3 views
0

Я пытаюсь протестировать программу, и каждый раз, когда я собираюсь ее скомпилировать, я получаю error LNK2019: unresolved external symbol "public: __thiscall Prog3Graph::Prog3Graph(void)" ([email protected]@[email protected]) referenced in function _main.. Мне было интересно, что вызывает это и как я могу это исправить. Я пробовал общаться с кодом, но не могу понять, что его вызывает.LNK2019 Неразрешенный внешний символ Справка

Prog3Graph.cpp:

#include <iostream> 
#include <fstream> 
#include <string.h> 
#include <stdlib.h> 
#include "Prog3Graph.h" 
#include "GraphNode.h" 
using namespace std; 
int main() 
{ 
    Prog3Graph *test; 
    test = new Prog3Graph(); 
    test->buildGraph("Graph.txt"); 
    test->printGraph(); 
    return 0; 
} 

bool Prog3Graph::buildGraph(char *fileName) 
{ 
    int i,j,index,numlinks, link; 
    char line[24]; 
    ifstream inFile; 
    inFile.open(fileName, ifstream::in); 
    if(!inFile.is_open()) 
    { 
     cout << "Unable to open file " << fileName << ". \nProgram terminating...\n"; 
     return 0; 
    } 
    for(i=0;i<10;i++) 
    { 
     getNextLine(line,24); 
     index = atoi(line); 
     Nodes[i].setNodeID(index); 
     getNextLine(line,24); 
     Nodes[i].setNodeData(line); 
     getNextLine(line,24); 
     numlinks = atoi(line); 
     for(j=0;j<numlinks;j++) 
     { 
      getNextLine(line,24); 
      link = atoi(line); 
      AdjMatrix[i][link]=1; 
     } 
     inFile.close(); 
    } 
    return true; 
} 
void Prog3Graph::printGraph() 
{ 
    int i,j; 
    cout << "------------------------------------------------------------\n\n"; 
    cout << " Adjacency Matrix:\n\n"; 
    cout << " 0 1 2 3 4 5 6 7 8 9\n"; 
    cout << " +---------------+\n"; 

    for(i=0; i<10; i++) 
    { 
     cout << i << "|"; 
     for(j=0; j<10; j++) 
     { 
      cout << AdjMatrix[i][j] << "|"; 
     } 
     cout << "\n +---------------+\n"; 
    } 
} 

bool Prog3Graph::getNextLine(char *line, int lineLen) 
{ 
    int done = false; 
    ifstream inFile; 
    while(!done) 
    { 
     inFile.getline(line, lineLen); 

     if(inFile.good()) 
     { 
      if(strlen(line) == 0) 
       continue; 
      else if(line[0] == '#') 
       continue; 
      else done = true;  
     } 
     else 
     { 
      strcpy(line, ""); 
      return false;  
     } 
    } 
    return true; 
} 

Prog3Graph.h:

#pragma once 
#include <iostream> 
#include <fstream> 
#include <string.h> 
#include <stdlib.h> 
#include "GraphNode.h" 

using namespace std; 


class Prog3Graph 
{ 
    private: 
      ifstream inFile;   // File stream to read from 
      int  AdjMatrix[10][10]; 
      GraphNode Nodes[10]; 

    public: 
      Prog3Graph();      // Class constructor 
      ~Prog3Graph();     // Class destructor 
      bool buildGraph(char *filename); // Read graph file, build graph 
      void printGraph();    // Print all data in graph 
      void depthFirstTraversal();  // Perform a depth first traversal 
    private: 
      bool getNextLine(char *line, int lineLen); // Read next line from graph file 
}; 

GraphNode.cpp:

#include <iostream> 
#include <fstream> 
#include <string.h> 
#include <stdlib.h> 
#include "GraphNode.h" 
using namespace std; 
void GraphNode::setNodeID(int ID) 
{ 
    m_iNodeID = ID; 
} 
int GraphNode::getNodeID() 
{ 
    return m_iNodeID; 
} 
void GraphNode::setNodeData(char *data) 
{ 
    int i; 
    for(i=0;i<24;i++) 
    { 
     m_sNodeData[i] = data[i]; 
    } 
} 
char *GraphNode::getNodeData() 
{ 
    return &m_sNodeData[24]; 
} 
void GraphNode::setVisited(bool visited) 
{ 
    m_bVisited = visited; 
} 
bool GraphNode::hasBeenVisited() 
{ 
    return m_bVisited; 
} 

GraphNode.h:

#pragma once 
#include <iostream> 
#include <fstream> 
#include <string.h> 
#include <stdlib.h> 

using namespace std; 



class GraphNode 
{ 
    private: 
      int m_iNodeID; 
      char m_sNodeData[24]; 
      bool m_bVisited; 
    public: 
      GraphNode();      
      ~GraphNode();      
      void setNodeID(int ID); 
      int getNodeID(); 
      void setNodeData(char *data); 
      char *getNodeData(); 
      void setVisited(bool visited); 
      bool hasBeenVisited(); 
}; 
+0

Добро пожаловать в SO! Однако это не служба поддержки. Сначала прочитайте документацию своего компоновщика. –

+0

@ DanielKamilKozar, действительно, и к счастью, это * есть *. – Roddy

+1

Вы объявили конструктор и деструктор 'Prog3Graph' в заголовочном файле' Pro3Graph.h', но не реализовали * ни *. Поэтому неудивительно, что в момент ссылки есть неразрешенный символ. (Примечание: вы также не реализовали 'depthFirstTraversal'). – WhozCraig

ответ

2

Внимательно прочитайте сообщение:

неразрешенный внешний символ "общественность: __thiscall Prog3Graph :: Prog3Graph (аннулируются)" (?? 0Prog3Graph @@ QAE @ XZ) ссылка в функции _MAIN.

Вы объявили конструктор (и деструктор) для своего класса, но вы его на самом деле не определяли.

Смежные вопросы