嵌套类问题
帮我看下这个程序,然后帮我讲解下。我实在是不明白。O(∩_∩)O谢谢先!
程序代码:#include "stdafx.h"
#include <iostream>
using namespace std;
class CA
{
public:
CA(){cout<<"This is the constructor of CA"<<endl;}
~CA(){cout<<"This is the destructor of CA"<<endl;}
};
class CB
{
CA a;//只知道这里是类的组合
public:
CB(){cout<<"This is the constructor of CB"<<endl;}
~CB(){cout<<"This is the constructor of CB"<<endl;}
};
void fun(int n)
{
static CA a;//这里不清楚为啥定义静态
CB b;
cout<<"n="<<n<<endl;
}
void main()
{
fun(10);
fun(20);
CA *A;//这里不明白
CB *pb=new CB;//这里也是
delete pb;
}
[ 本帖最后由 大剑 于 2012-2-18 11:55 编辑 ]








