[英]Error : out-of-line definition , I don't know how to solve it
我有一个错误:“setShortPath”和“setNodePath”的外线定义与“MyGraphBuilder”中的任何声明都不匹配 CPP 中的代码是:
// Mutator
void MyGraphBuilder::setShortPath(vector <Vertex> PathVector)
{
ShortPath.clear();
ShortPath = PathVector;
}
void MyGraphBuilder::setNodePath(Vertex MyNode){
ShortPath.emplace_back(MyNode);
};
而 Header 文件中的代码为:
//Mutators
// function to assign Shortest path as a whole Vectore
void setShortPath(std::vector <Vertex> PathVector);
// function to assign Shortest path Vertex by Vertex
void setNodePath(Vertex);
除非您已声明using namespace std;
在您的 cpp 中,由于在vector
之前的定义中缺少std::
,因此声明和定义可能不匹配。 你也不需要;
在setNodePath
定义之后。
// Mutator
void MyGraphBuilder::setShortPath(std::vector <Vertex> PathVector)
{
ShortPath.clear();
ShortPath = PathVector;
}
void MyGraphBuilder::setNodePath(Vertex MyNode){
ShortPath.emplace_back(MyNode);
}
请注意 'setNodePath' function 正文的右大括号后的分号:
void MyGraphBuilder::setNodePath(Vertex MyNode){
ShortPath.emplace_back(MyNode);
}; <----
我认为这是您的问题的根源或根源之一。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.