错误我无法追踪
Error I cant track down
我不明白为什么会发生这个错误我很困惑。
错误1错误LNK2019:未解析的外部符号"public:__thiscall Graph::Leingth::Leingth(void)"(??0Leingth@Graph@@QAE@XZ)在函数"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错误2错误LNK1120:1个未解析的外部文件C:\Users\kevin\Documents\Visual Studio 2013\Projects\Project7\Debug\Project7.exe 1 1 Project7
主
#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;
}
图形程序
#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;
};
您已经声明了Graph::Leingth
的默认构造函数,但尚未在任何地方定义它。
更改线路
Leingth();
至
Leingth() {}
这应该能解决问题。
PS您是想用拼写错误的Leingth
而不是拼写正确的Length
吗?
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- Project Euler问题4的错误解决方案
- 我的字符计数代码计算错误.为什么
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- 在某些循环内使用vector.push_back时出现分段错误
- C++:光线追踪器导致内存不足错误 - 由于反复调用"new"?
- 错误我无法追踪
- c++代码中涉及类的无法追踪的错误
- 我无法追踪可能的复制构造错误