————Main.cpp
#include <iostream> //headfile通常用来声明某种类型的函数,以便他们用于程序
//#include具备复制文件内容,粘贴到另一文件的功能
//iostream没有后缀是为了区分c标准库和c++标准库
#include "Log.h" //""包含相对于当前文件的文件
//eg.如果有一个文件在log.cpp文件所在目录的上层目录下 用include "../ .h"
//<>只用于编译器包含路径,""可以做一切
int main()
{
InitLog();
Log("HelloWorld");
std::cin.get();
}
————Log.cpp
#include "Log.h"
#include <iostream>
void InitLog()
{
Log("Initializing Log");
}
void Log(const char* message)
{
std::cout << message << std::endl;
}
————Log.h
#pragma once //only include this file once,监督作用
//#开头被称为预处理命令或预处理指令
void Log(const char* message);
void InitLog();
————common.h
#ifndef _LOG_H//检查是否有一个叫_LOG_H的符号被定义,true则向下编译,flase则以下内容will not be included(和#pragma once功能一致)
#define _LOG_H
#include "log.h"
#endif
#pragma once 注释后的错误
——————Log.h
//#pragma once
void Log(const char* message);
void InitLog();
struct Player{};
————Main.cpp
#include <iostream>
#include "Log.h"
#include "Log.h"//编译出错,定义Player结构体错误
int main()
{
InitLog();
Log("HelloWorld");
std::cin.get();
}