标题:复制构造函数
取消只看楼主
大剑
Rank: 2
等 级:论坛游民
帖 子:30
专家分:25
注 册:2011-11-16
结帖率:100%
已结贴  问题点数:20 回复次数:0 
复制构造函数
复制构造函数在那?
程序代码:
#include "stdafx.h"
#include <iostream>
using namespace std;
class CStudent
{
private:
    char *p_name;
    int age;
public:
    CStudent(char *,int);
    ~CStudent() {
        if(p_name!=NULL)
            delete p_name;
        cout<<"destructor of class"<<endl;
    }
    void show(void);
};
CStudent::CStudent(char *source,int a)
{
    p_name=new(char[strlen(source)+1]);
    strcpy(p_name,source);
    age=a;
}
void CStudent::show()
{
    cout<<p_name<<" "<<age<<endl;
}
void main()
{
    CStudent *p_student=new CStudent("张三",20);
    CStudent stud1("李四",50);
    CStudent stud3(stud1);

    p_student->show();
    stud1.show();
    stud3.show();
    delete p_student;
}


出现这个状况 那位帅哥帮忙解释下。

搜索更多相关主题的帖子: 函数 
2012-02-15 13:27



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




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

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