『C++』Temp_2019_03_14 不同类的循环引用

 1 #include <iostream>
 2 #include <string>
 3 #include <regex>
 4 using namespace std;
 5 
 6 //提前声明类
 7 class A;
 8 class B;
 9 
10 //进行正式类定义
11 class A{
12 public:
13     string Name;
14     B* BPtr;
15 };
16 
17 class B{
18 public:
19     string Name;
20     A* APtr;
21 };
22 
23 
24 
25 int main(){
26     A* a =new A();
27     B* b =new B();
28 
29     a->Name="张三";
30     b->Name="李四";
31     a->BPtr=b;
32     b->APtr=a;
33 
34     cout<<a->Name<<endl;        //张三
35     cout<<a->BPtr->Name<<endl;  //李四
36 
37     cin.get();
38 }

 

posted @ 2019-03-14 18:36  redc  阅读(224)  评论(0编辑  收藏  举报