请提供LNK2019无法解析的外部符号帮助

LNK2019 Unresolved External Symbol Help Please

本文关键字:外部 符号 帮助 LNK2019      更新时间:2023-10-16

我正在尝试测试一个程序,每次编译它时,我都会得到error LNK2019: unresolved external symbol "public: __thiscall Prog3Graph::Prog3Graph(void)" (??0Prog3Graph@@QAE@XZ) referenced in function _main.。我想知道是什么导致了这种情况,以及如何修复它

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 << "------------------------------------------------------------nn";
    cout << " Adjacency Matrix:nn";
    cout << "  0 1 2 3 4 5 6 7 8 9n";
    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;
}

Prog3图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();
};

仔细阅读消息:

未解析的外部符号"public:__thiscallProg3Graph::Prog3Graph(void)"(??0Prog3Graphic@@QAE@XZ)在函数_main中引用。

您已经为类声明了一个构造函数(和一个析构函数),但从未真正定义过它们。