为什么包含 a 的定义并被多个源文件包含的头文件不给出编译错误?const
multiple definition
const_in_header_file.h
const int num = 5;
//int x; //Error. Multiple defintion if included from multiple source files.
const_in_header_file_func.cpp
#include <iostream>
#include "const_in_header_file.h"
using namespace std;
void func(void)
{
cout << "num in func() = " << num << endl;
}
const_in_header_file_main.cpp
#include <iostream>
#include "const_in_header_file.h"
using namespace std;
extern void func(void);
int main()
{
cout << "num in main() = " << num << endl;
func();
}