注意事项
例1:一个project中包含三个文件
test1.cpp
#include <stdio.h> #include "test2.h" int main(){ printf("a=%d\n",a); return 0; }
test2.h
extern int a;
test2.cpp
int a = 10;
>>a = 10
例2:
写法一:
//=============A.h start====================
#include <B.h>
class A
{
private:
B * impl;
};
//=============A.h end====================
写法二:
//=============A.h start====================
class B;
class A
{
private:
B * impl;
};
//=============A.h end====================
//=============A.cpp start====================
#include <A.h>
#include <B.h>
// 其他具体实现
........
//=============A.cpp end====================
写法一是使用前定义;写法二是使用前声明,随后定义
参考:
https://blog.csdn.net/skk18739788475/article/details/79643978
https://blog.csdn.net/CC_20171030/article/details/78557723
原文:https://www.cnblogs.com/cxc1357/p/11809832.html