提问人:Ishan Rana 提问时间:4/28/2021 最后编辑:Ishan Rana 更新时间:4/28/2021 访问量:281
C++ 错误“未定义对 Class::Function() 的引用 [重复]
C++ error 'Undefined reference to Class::Function() [duplicate]
问:
我只是想知道是否有人可以帮助我解决这个问题,我是 C++ 的新手,当我将类分成不同的文件时遇到了问题。
编译 SepMain.cpp 文件时遇到的错误是:
/usr/bin/ld: /tmp/cciHobHn.o: in function `main':
SepMain.cpp:(.text+0x23): undefined reference to `Sep::Sep()'
collect2: error: ld returned 1 exit status
编译 Sep.cpp 文件时遇到的错误是:
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
collect2: error: ld returned 1 exit status
编译 Sep.h 文件时遇到的错误是:
bash: /home/ishan/Coding/C++/Learn/tempCodeRunnerFile: Permission denied
所以我的代码有三个文件:
九月.cpp
#include "Sep.h"
#include <iostream>
using namespace std;
Sep::Sep()
{
cout<<"hello"<<endl;
}
9月,
#ifndef SEP_H
#define SEP_H
class Sep
{
public:
Sep();
};
#endif
SepMain.cpp
#include "Sep.h"
#include <iostream>
using namespace std;
int main()
{
Sep ir;
return 0;
}
答: 暂无答案
评论