c ++中的标题保护

时间:2016-09-01 17:22:13

标签: c++

大家好,我只是通过c ++中的标题保护应用程序查看,我知道标题保护用于同时包含任何文件的内容,我有以下情况,

A.H

#include<string>
#include "b.h"
std::string getA()
{
    return "A";
}

b.h

#include<string>
#include "a.h"
#ifndef B_H
#define B_H
std::string getB()
{
    return "B";
}
#endif

both.cpp

#include<iostream>
#include"b.h"
#include"a.h"
using namespace std;
int main()
{
    cout<<getA();
    cout<<getB();
    return 0;
}

请解释我最终的both.cpp是如何包含的,因为我们有两次被称为“#include”b.h“”。我想我在这里有意义。提前谢谢。请帮助需要的人。 由于a.h没有头文件保护,并且getA的函数定义应该在both.cpp中包含2次,但是程序运行成功。请帮我弄清楚最终的两个.cpp代码。

0 个答案:

没有答案