C++之导入其他文件的函数

C++之导入其他文件的函数

相信很多小伙伴在开发的时候,都需要在自己的主文件中导入自己写好的其他文件中的函数,那么具体应该怎么做呢?下面我们来看一个例子
在这里插入图片描述
上述图片中的代码是要在主文件中准备调用的test_202(),下面演示一下如何在主文件中调用

#include <iostream>
#include "opencv2/opencv.hpp"
//错误写法 #include "test.cpp"
using namespace std;
using namespace cv;

//声明这个函数
void test_202();

int main() {
    
    
    test_202();
    return 0;

}
输出:
this is a test202 file

上述程序中可以看到如果使用#include引入了test.cpp,那么其实会报bugmultiple definition of `test_202(),就是函数名冲突的问题。正确写法是直接在主文件中声明要调用的函数,然后在main()中直接调用即可。

猜你喜欢

转载自blog.csdn.net/qq_35140742/article/details/119914050
今日推荐