
C++
// func1.h#ifndef FUNC1_H#define FUNC1_Hint f1(int num);#endif// func1.cpp#include "func1.h"int f1(int num) { return num * 2; }// func2.h#ifndef FUNC2_H#define FUNC2_Hint g1(int num);int g2(int num);#endif// func2.cpp#include "func2.h"int g1(int num) { return num * 3; }int g2(int num) { return num * 4; }// constant.h#ifndef CONSTANT_H#define CONSTANT_Hconst int YEARDAYS = 365;const int WON = 1;const int TUE = 2;const int WED = 3;const int THU = 4;const int FRI = 5;const int STA = 6;const int SUN = 7;#endif这个示例展示了如何在C++中使用头文件定义函数和常量,并避免在不同源文件之间出现冲突。
Copyright © 2025 IZhiDa.com All Rights Reserved.
知答 版权所有 粤ICP备2023042255号