尝试访问另一个文件中的类时出现"未定义的引用"

'Undefined Reference' when trying to access class in another file

本文关键字:未定义 引用 另一个 文件 访问      更新时间:2023-10-16

所以基本上我正在制作这个简单的程序,添加数字,但不断得到错误'对tent::boom的未定义引用'。我已经对代码进行了几个小时的修修补补,并查看了许多不同的解决方案,但由于任何原因,它们似乎都不起作用,所以我很抱歉,如果这个问题的类似版本已经被问过了。

//main.cpp
#include <iostream>
#include "tent.h"

using namespace std;

int main()
{
    tent bo;
    bo.boom();
    return 0;
}
//tent.h
#include <iostream>
class tent
{
public:
    tent();
    int boom();
protected:
private:
};
//tent.cpp
#include "tent.h"
#include <iostream>

using namespace std;
int boom()
{
    int a;
    int b;
    int c = a + b;
    cin >> a;
    cin >> b;
    cout << c << endl;
    return 0;
}

我所做的是将boom in tent.cpp改为tent::boom