.cpp文件中未定义的引用错误

undefined reference error in the .cpp file

本文关键字:引用 错误 未定义 文件 cpp      更新时间:2023-10-16

我正在尝试编写一个函数,该函数将迭代器返回到具有正确字符串标识符的"节点"(我创建的对象(:

list<node>::iterator point_component_from_out(const string out,const list<list<node>>::iterator &row){
list<node>::iterator it=row->begin(),r_it=row->begin();
vector<string> vct;
it++;
for(it;it!=row->end();it++){
vct=it->get_outputs_labels();
for(vector<string>::iterator vct_it=vct.begin();vct_it!=vct.end();vct_it++){
if(*vct_it==out){
r_it=it;
}
}
}
return r_it;
}

现在我从另一个函数调用这个函数,该函数与前一个函数位于同一个.cpp文件中。 (函数的一小部分(:

void graph::build_chain(string out,list<list<node>>::iterator row){
list<node>::iterator it_node,support_it;
list<list<node>>::iterator new_row;
string new_out;
int i=0;
vector<string> declared_outputs,linked_outputs,declared_inputs,linked_inputs;
//funzione che ritorna l'iteratore che punta alla porta con quell'out
it_node=point_component_from_out(out,row);

此时,当我构建项目时,我从构建器收到此错误:

undefined reference to `graph::point_component_from_out(std::string, std::_List_iterator<std::list<node, std::allocator<node> > > const&)'
relocation truncated to fit: R_X86_64_PC32 against undefined symbol `graph::point_component_from_out(std::string, std::_List_iterator<std::list<node, std::allocator<node> > > const&)'

如果我单击错误,它会显示它指的是我向您展示的第二个代码的最后一行。

如果您正在编写point_component_from_out作为函数的实现 - 请确保它在graph::build_chain函数之前,如果point_component_from_out也是类成员并且您正在为方法编写实现 - 请检查您是否忘记了类说明符:MyClass::method