📄 14-14.txt
字号:
/* 范例:14-14 */
#include <iostream.h>
class A
{
private:
class B
{
public:
int c;
int d;
/* 属于“嵌套类”的成员函数参数列设定“外围类”A类型的mythis对象指针
变量*/
void Bfun(A* mythis)
{
mythis->a=100; //存取外围类的成员
mythis->b=50;
cout<<"mythis->a="<<mythis->a<<"\tmythis->b="
<<mythis->b<<endl;
}
};
public:
B obj2; /* 以嵌套类B为类型,定义数据成员obj2 */
int a;
int b;
/* 参数行中以嵌套类B为类型,定义区域变量mythis */
void Afun(B* mythis)
{
mythis->c=150; //存取嵌套类的成员
mythis->d=200;
cout<<"mythis->c="<<mythis->c<<"\tmythis->d="
<<mythis->d<<endl;
}
};
void main()
{
A obj1;
obj1.Afun(&obj1.obj2);
obj1.obj2.Bfun(&obj1);
getchar();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -