互包含的类
源程序:
<style></style>#include<iostream>
#include<string>
using namespace std;
class B;
class A
{
public:
int aInt;
B *bPoint=NULL;
void SetValue(int v)
{
aInt=v;
}
};
class B
{
public:
A aCla;
int bInt;
void SetValue(int v)
{
bInt=v;
}
};
int main()
{
A ca;
B cb;
ca.bPoint=&cb;
cout<<"ca.bPoint="<<ca.bPoint<<endl;
cout<<"cb Addr="<<&cb<<endl;
cout<<"ca.aInt="<<ca.aInt<<endl;
cout<<"ca.aCla.aInt="<<cb.aCla.aInt<<endl;
cout<<"cb.bInt="<<cb.bInt<<endl;
cout<<"分界线"<<endl;
ca.SetValue(10);
ca.SetValue(20);
cb.aCla=ca;
cout<<"ca.bPoint="<<ca.bPoint<<endl;b
cout<<"ca.aInt="<<ca.aInt<<endl;
cout<<"ca.aCla.aInt="<<cb.aCla.aInt<<endl;
cout<<"cb.bInt="<<cb.bInt<<endl;
return 0;
}
运行结果: