Pergunta

I'm trying to test a program and every time I go to compile it, I get the error LNK2019: unresolved external symbol "public: __thiscall Prog3Graph::Prog3Graph(void)" (??0Prog3Graph@@QAE@XZ) referenced in function _main. I was wondering what is causing this and how I can fix it. I've tried messing around with the code, but can't figure what is causing it.

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();
};
Foi útil?

Solução

Read the message carefully:

unresolved external symbol "public: __thiscall Prog3Graph::Prog3Graph(void)" (??0Prog3Graph@@QAE@XZ) referenced in function _main.

You've declared a constructor (and a destructor) for your class, but you've never actually defined them.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top