c++ - C++ 错误'未定义的对 Class::Function() 的引用
问题描述
我只是想知道是否有人可以帮助我解决这个问题,我是 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;
}
九月
#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;
}
解决方案
推荐阅读
- php - Laravel jwt 在组外使用中间件
- java - 在 JavaFX 中闪烁一个矩形
- sql - 重命名sql server中现有表中的列,其中列名为空
- apache-spark - 对远程火花大师执行“火花提交”很热吗?
- typescript - Vue.set - TypeScript 推断的错误类型
- android - 测试传感器正常工作的常用方法有哪些
- google-analytics - GoogleAnalytics API:有没有办法通过特定的会话 id 获取数据?
- javascript - 如何使用 jquery 或 javascript 选择第一个收音机作为默认值
- java - 使用 Java 的 gRPC 中的 OAuth
- solr - 在基于 lucene 的露天社区版上安装 Solr