Во-первых, как упомянул @LuisGP, вам нужен #ifndef, если ваш заголовочный файл включен много раз.Во-вторых, в связанный cpp-файл вам необходимо включить заголовочный файл.Заголовочный файл объявляет функцию, файл cpp описывает функцию.Наконец, все файлы cpp должны быть включены при компиляции (просто используйте командную строку, если редактор не работает).Это выглядит так:
gcc -c my_function.cpp file_b.cpp //this will make a my_function.o and a file_b.o file
gcc -o main main.cpp my_function.o file_b.o
или для краткости:
gcc -o main main.cpp my_function.cpp file_b.cpp
Вот как должны записываться файлы:
// my_function.h
#ifndef _my_function_h
#define _my_function_h
void func_i_want_to_include();
#endif
// my_function.cpp
#include <stdio.h>
#include "my_function.h"
void func_i_want_to_include()
{
puts("hello world");
}
//file_b.h
#ifndef _file_b_h
#define _file_b_h
void call_to_file_b();
#endif
//file_b.cpp
#include <stdio.h>
#include "my_function.h"
#include "file_b.h"
void call_to_file_b()
{
puts("from file b\n");
func_i_want_to_include();
}
//main.cpp
#include "my_function.h"
#include "file_b.h"
int main()
{
call_to_file_b();
func_i_want_to_include();
return 0;
}
Это мой первый разОтвечая на вопрос, если я сделаю какую-либо ошибку, скажите мне, и я исправлю это.Надеюсь, это поможет.