自考新教材-p228
作者:互联网
互包含的类
源程序:
<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;
}
运行结果:
标签:p228,SetValue,cout,新教材,cb,ca,int,class,自考 来源: https://www.cnblogs.com/duanqibo/p/12183476.html