对功能的未定义引用

问题描述 投票:0回答:1

我真的不明白为什么它不能正常工作。

尝试制作程序时出错

[ 14%] Linking CXX executable a.out
CMakeFiles/a.out.dir/main.cpp.o: In function `main':
main.cpp:21: undefined reference to `transfertoList(std::basic_fstream<char, std::char_traits<char> >&, ListofList&)'
collect2: error: ld returned 1 exit status
CMakeFiles/a.out.dir/build.make:224: recipe for target 'a.out' failed
make[2]: *** [a.out] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/a.out.dir/all' failed
make[1]: *** [CMakeFiles/a.out.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

主要使用f-ion

transfertoList(file, table);

原型

void transfertoList(fstream &file, ListofList &list);

实现

void transfertoList(fstream file, ListofList &list)
{
    while (1) {
        string temp, t;
        getline(file, temp);
        stringstream ss(temp);

        while (getline(ss, t, ',')) {
            List *m;
            m = new List;
            (*m).add(t);
            list.add(m);
        }

        if (file.eof()) break;
    }
}
c++ function fstream
1个回答
0
投票
您的原型用于此功能

void transfertoList(fstream &file, ListofList &list);

但是您可以用此原型定义一个函数

void transfertoList(fstream file, ListofList &list)

更改您的定义以使用引用(fstream &file),或将原型更改为不使用引用(fstream file)。我更喜欢前者。
© www.soinside.com 2019 - 2024. All rights reserved.