首页 > 解决方案 > .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&)'

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

标签: c++objectreferencelinker

解决方案


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


推荐阅读