65,210
社区成员
发帖
与我相关
我的任务
分享
#include <iostream.h>
class A
{
public:
A()
{
cout << "this is A" << endl;
}
~A(){}
void outputA()
{
cout << "outputA" << x << y << endl;
}
int x;
int y;
};
class B
{
public:
B()
{
cout << "this is B" << endl;
//pA = NULL;
pA=new A; //记得给A分配空间
}
~B(){delete pA;} //删除空间
void outputB(int m,int n)
{
cout << "outputB" << endl;
pA->x=m;
pA->y=n;
pA->outputA();
}
A *pA;
};
int main()
{
B cB;
cB.outputB(4,3);
cout << cB.pA->x << endl << cB.pA->y << endl;
return 0;
}
#include <iostream.h>
class A
{
public:
A()
{
cout < < "this is A" < < endl;
}
~A(){}
void outputA()
{
cout < < "outputA" < < x < < y < < endl;
}
int x;
int y;
};
class B
{
public:
B()
{
cout < < "this is B" < < endl;
pA = NULL;
}
~B(){}
void outputB(int m,int n)
{
cout < < "outputB" < < endl;
pA->x=m;
pA->y=n;
pA->outputA();
}
A *pA;
};
int main()
{
B cB;
cB.outputB(4,3);
cout < < cB.pA->x < < endl < < cB.pA->y < < endl;
return 0;
}