c++ - 如何使用头文件声明在另一个 cpp 文件中定义的函数以在我的主文件中使用?
问题描述
我知道这可能以前已经回答过,但我已经尝试过答案,但它们不起作用。我有一个头文件(test declaration.h)和一个 cpp 文件(test.cpp 的定义),最后是一个主 cpp 文件(main.cpp)。当我编译并运行该项目时,我收到一个错误(C3861 'test': identifier not found)。所有文件都在同一个文件夹中。我正在使用 Visual Studio 2019。为什么会发生这种情况,我做错了什么?
编辑
我已将文件更改为没有空格,现在出现链接错误(LNK2019 unresolved external symbol "void __cdecl test(void)" (?test@@YAXXZ) referenced in function _main)
测试定义文件
#include <iostream>
#include "test declaration.h"
using namespace std;
void test()
{
cout << "hi";
}
测试decl.h
#pragma once
void test();
主文件
#include <iostream>
#include "test declaration.h"
int main()
{
test();
}
解决方案
推荐阅读
- r - R:在函数中循环以填充数据框
- sweetalert2 - Sweetalert2:删除应用于元素的内联样式
- firebase - 如何从子集合文档中获取数据,firestore(Flutter)
- angular - 为什么我的标题没有在这个简单的 Angular 应用程序中呈现?
- php - 在 PHP 递归函数内部返回
- django - 在 JSON 数组字段中使用主键构建 django 查询集
- javascript - 遇到数字时将字符串拆分为正好两部分的数组
- javascript - 分配给父 div 的事件侦听器在按钮上停止
- sql - 我想在订单交付后减少产品数量 laravel 7
- c# - 在调用 ShowDialog 之后/期间使用异步值更新 ViewModel