对外部类的未定义引用
Undefined reference to an external class
C:UsersPCDesktoprandommain.o:main.cpp:(.text+0x76)||undefined reference to `Tclass::FFunction()'|
我创建了自己的类,该类位于主程序的外部,这是我遇到的错误。这是我的程序的代码。
主程序(.cpp)
#include<iostream>
#include "Tclass.h"
#include "Tclass.cpp"
using namespace std;
int main(){
Tclass object;
object.FFunction();
return 0;
}
头文件。(.h)
#ifndef TCLASS_H
#define TCLASS_H
class Tclass
{
public:
Tclass();
void FFunction();
};
#endif // TCLASS_H
C ++样式表(我认为这就是它的名字)(.cpp)
#include "Tclass.h"
#include<iostream>
using namespace std;
Tclass::Tclass()
{
cout << "An object for this class has been created n";
}
void FFunction(){
cout << "The function has been created n";
}
我正在使用代码::块作为我的IDE。我还创建了带有任何析构函数的类
在您的
.cpp文件中:
void Tclass::FFunction(){
cout << "The function has been created n";
}
而不是:
void FFunction(){
cout << "The function has been created n";
}
此外,无需将Tclass.cpp
包含在您的主目录中。
相关文章:
- 编译C++时未定义的引用
- 如何修复此错误:未定义对"距离(浮点数,浮点数,浮点数,浮点数,浮点数)"的引用
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 对C宏的未定义引用,但在定义它时会出现重新定义错误
- 未定义的引用在哪里
- 编译时的 CImg 库返回对"__imp_SetDIBitsToDevice"的未定义引用
- 对Py_Initialize()的未定义引用
- 使用mysql c++连接器的未定义引用
- 未定义的引用 .. 使用 OpenCV 编译 C++ 代码时,从命令行
- 对 Scalar ::Scalar() 的未定义引用
- 已定义函数时出现 G++ "未定义的引用"错误
- 链接 cmake 时出现未定义的引用错误
- 对复制 CTOR 和 CTOR 的未定义引用
- 错误:未定义对'oboe::AudioStreamBuilder::openStream(oboe::AudioStream**)'的引用
- 右值引用未定义的行为
- 对"vtable for DigitalClock"的未定义引用 - 未定义对"DigitalClock::staticMetaObject"的引用 - Qt
- 函数类型到函数类型的引用:未定义的引用
- avcodec_alloc_context引用未定义,但ffmpeg链接顺序正确
- 从c++调用Fortran子程序,链接时引用未定义
- 枚举引用未定义,但位于包含的头文件中