#ifndef 用法疑问
文件1
#ifndef 1
#define 1
#include<iostream>
#include <string>
using namespace std;
#endif
文件2
#ifndef 2
#define 2
#include<iostream>
#include <string>
using namespace std;
#endif
如果文件3同时#include<文件1>#include<文件2>那么#include<iostream>#include <string>不会被重复用吗,不太理解#ifndef 用法,求正解。
[解决办法]
string有它自己的#ifndef guard,第一次被包了以后第二次就不包了。
[解决办法]
#include <iostream>、#include <string>中也会有如下:
#ifndef IOSTREAM_H
#define IOSTREAM_H
//iostream类的定义
#endif
包含了一次就不会有包含第二次了,所以不会重复