c++ - .cpp 文件中未定义的引用错误
问题描述
我正在尝试编写一个函数,该函数将迭代器返回到具有正确字符串标识符的“节点”(我创建的对象)(下面的代码):
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
。
推荐阅读
- c# - C# 使用 StringBuilder 追加测试
- java - Mysql查询字符串减号(-)符号问题
- python - 无法使用带有 if 条件的列表推导从现有列表创建重复列表
- java - 在 Linux 集群错误上使用 Rscript 无头加载 NetLogo
- r - 从时间序列中的不同数据框中绘制多个具有相同名称的变量;ggplot2 tidyr
- python - 将列表与列进行比较并操作单元格
- python - 模拟 Popen 失败并出现异常
- java - 当另一个正在录制时,停止我的应用程序播放媒体
- python - TensorFlow - 时代准确度
- enums - Flutter / Dart 将 Int 转换为 Enum