c++/c中关于头文件的探索

次林梦叶的小屋 / 2023-09-05 / 原文

// Fin.h

#ifndef FIN_H
#define FIN_H

int add(int a, int b);

#endif

// Fin.cpp

#include "Fin.h"

int add(int a, int b) {
    return a + b;
}

// Test1.cpp

#include <iostream>
#include "Fin.h" // 包含Fin.h来调用函数

int main() {
    int result = add(3, 4);
    std::cout << "3 + 4 = " << result << std::endl;

    return 0;
}

 

 

   

 

   如上代码,这样使用头文件是没问题的

    但是如果想要用c++中如vector,我做了如下改变:

   

   

   

   这样就会报错:

   

   应该c++对这种要另外有什么处理,c用上面方法是没问题的