标题:嵌套类问题
取消只看楼主
大剑
Rank: 2
等 级:论坛游民
帖 子:30
专家分:25
注 册:2011-11-16
结帖率:100%
已结贴  问题点数:20 回复次数:1 
嵌套类问题
帮我看下这个程序,然后帮我讲解下。我实在是不明白。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 编辑 ]
搜索更多相关主题的帖子: 帕米尔 地球 
2012-02-18 11:50
大剑
Rank: 2
等 级:论坛游民
帖 子:30
专家分:25
注 册:2011-11-16
得分:0 
汗! 我会加油的!
2012-02-19 09:53



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-361124-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.146252 second(s), 9 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved