0
votes

I cannot figure out why this error is happening Im so confused.

Error 1 error LNK2019: unresolved external symbol "public: __thiscall Graph::Leingth::Leingth(void)" (??0Leingth@Graph@@QAE@XZ) referenced in function "public: __thiscall Graph::queMember::queMember(int,int,struct Graph::Leingth)" (??0queMember@Graph@@QAE@HHULeingth@1@@Z) C:\Users\kevin\Documents\Visual Studio 2013\Projects\Project7\Project7\Source.obj Project7 Error 2 error LNK1120: 1 unresolved externals C:\Users\kevin\Documents\Visual Studio 2013\Projects\Project7\Debug\Project7.exe 1 1 Project7

Main

#include <iostream>
#include <fstream>
#include "Graph.h"
#include <string>

using namespace std;

int main()
{
    Graph g(ifstream("Text.txt"));
    LCAPath p = g.ShortestCommonAncester(3, 5);
    cout << p.Leingth << endl << p.LeastCommonAncester << endl << p.path;
}

The Graph program

#pragma once
#include <iostream>
#include <fstream>

using namespace std;

struct LCAPath
{
    int LeastCommonAncester;
    int Leingth;
    string path = "";
};
class Graph
{
public:
    struct PathGroupMember
    {
        int Id = NULL; //THE NODE POINTED TO
        PathGroupMember * p = NULL;
        void add(int nextID)
        {
            if (Id = NULL)
            {
                Id = nextID;
            }
            else if (p = NULL)
            {
                p = new PathGroupMember();
                p->Id = nextID;
            }
            else p->add(nextID);
        }
    };
    struct Node
    {
        PathGroupMember * PathGroup = new PathGroupMember;
    };
    Graph(ifstream FStream)
    {
        if (FStream) FStream >> nodes;
        if (FStream) FStream >> paths;
        NodeList = new Node[nodes];
        for (int i = 0; i < paths; i++)
        {
            if (FStream)
            {
                int temp1;
                int temp2;
                FStream >> temp1;
                if (FStream)
                {
                    FStream >> temp2;
                    NodeList[temp1].PathGroup->add(temp2);
                }
            }
        }
    }
    LCAPath ShortestCommonAncester(int a, int b)
    {
        int* aa = new int[1];
        int* bb = new int[1];
        aa[0] = a;
        bb[0] = b;
        return ShortestCommonAncestor(aa, 1, bb, 1);
    }
    struct Leingth
    {
        Leingth();
        Leingth(int a, int b, string aa, string bb)
        {
            FromA = a;
            FromB = b;
            PathA = aa;
            PathB = bb;
        }
        int FromA = -1;
        int FromB = -1;
        string PathA = "";
        string PathB = "";
    };
    struct queMember
    {
        int Fromnode;
        int Tonode;
        Leingth l;

        queMember(int From, int To, Leingth L)
        {
            Fromnode = From;
            Tonode = To;
            l = Leingth(L);
        }

        queMember * next = NULL;
    };
    struct que
    {
        queMember * Front;
        queMember * Back;
        void add(queMember* M)
        {
            if (Front == NULL) Front = M;
            Back->next = M;
            Back = M;
        }
        queMember* remove()
        {
            if (Front = NULL) return NULL;
            queMember * temp = Front;
            Front = Front->next;
            return temp;
        }
        bool hasNext()
        {
            if (Front == NULL)return false; return true;
        }
    };
    LCAPath ShortestCommonAncestor(int* a, int GroupASize, int*b, int GroupBSize)
    {

        Leingth* BestLeingthList = new Leingth[nodes];
        que q;
        for (int i = 0; i < GroupASize; i++)
        {
            for (PathGroupMember* p = NodeList[a[i]].PathGroup; p != NULL; p = p->p)
            {
                queMember* t = new queMember(i, p->Id, Leingth(1,0,(i +"-" + p->Id),""));
                q.add(t);
            }
        }

        while (q.hasNext())
        {
            queMember * t = q.remove();
            if (t->l.FromA < BestLeingthList[t->Tonode].FromA)
            {
                BestLeingthList[t->Tonode] = t->l;
                for (PathGroupMember* p = NodeList[t->Tonode].PathGroup; p != NULL; p = p->p)
                {
                    string path = t->l.PathA + "-";
                    path += p->Id;
                    queMember* temp = new queMember(t->Fromnode, p->Id, Leingth(t->l.FromA + 1, 0, path, ""));
                    q.add(temp);
                }
            }
        }

        for (int i = 0; i < GroupBSize; i++)
        {
            for (PathGroupMember* p = NodeList[b[i]].PathGroup; p != NULL; p = p->p)
            {
                queMember* t = new queMember(i, p->Id, Leingth(0, 1, "", (p->Id + "-" + i)));
                q.add(t);
            }
        }
        int best = -1;
        while (q.hasNext())
        {
            queMember * t = q.remove();
            if (t->l.FromB < BestLeingthList[t->Tonode].FromB)
            {
                BestLeingthList[t->Tonode].FromB = t->l.FromB;
                BestLeingthList[t->Tonode].PathB = t->l.PathB;


                if (BestLeingthList[t->Tonode].FromB + BestLeingthList[t->Tonode].FromA < BestLeingthList[best].FromB + BestLeingthList[best].FromA || (best = -1))
                    best = t->Tonode;
                for (PathGroupMember* p = NodeList[t->Tonode].PathGroup; p != NULL; p = p->p)
                {
                    string path = p->Id + " " + t->l.PathB;
                    queMember* temp = new queMember(t->Fromnode, p->Id, Leingth(0, t->l.FromB + 1, "", path));
                    q.add(temp);
                }
            }
        }
        LCAPath returnval;
        returnval.LeastCommonAncester = best;
        returnval.Leingth = BestLeingthList[best].FromA + BestLeingthList[best].FromB;
        returnval.path = BestLeingthList[best].PathA + BestLeingthList[best].PathB;
        return returnval;
    }
private:
    int nodes;
    int paths;
    Node * NodeList;
};
1
if (Id = NULL) in method Graph::PathGroupMember::addis always true. Perhaps you should use == instead. - Ari0nhh
Thanks after I got the base error down I found that. - Kevin Hall
Now im getting an error for Access violation that causes the program to go unresponsive. Its in Struct que add Back->next = M; - Kevin Hall
Your if ( Fstream ) tests are in the wrong place. You should test after reading, and before using the results of the read. - M.M

1 Answers

1
votes

You have declared the default constructor of Graph::Leingth but you haven't defined it anywhere.

Change the line

    Leingth();

to

    Leingth() {}

That should fix it.

PS Did you mean to use the incorrectly spelled Leingth instead of the correctly spelled Length?