标题:关于默认拷贝函数
取消只看楼主
karlzhouzhi
Rank: 1
等 级:新手上路
帖 子:70
专家分:0
注 册:2005-12-25
 问题点数:0 回复次数:0 
关于默认拷贝函数

#include <iostream.h>
#include<string.h>

class Student
{
public:
Student(char *pName="no name")
{
cout<<"constructing new student "<<pName<<endl;
strcpy(name,pName);
name[sizeof(name)-1]='\0';
}

Student(Student &s)
{
cout<<"constructing copy of "<<s.name<<endl;
strcpy(name,"copy of ");
strcat(name,s.name);
}
~Student()
{
cout<<"destructing "<<name<<endl;
}
protected:
char name[40];
};

class Tutor
{
public:
Tutor(Student &s):student(s)
{
cout<<"Constructing tutor"<<endl;
}
protected:
Student student;
};

void fn(Tutor tutor)
{
cout<<"In function fn()"<<endl;
}
void main()
{
Student randy("randy");
Tutor tutor(randy);
cout<<"calling fn()"<<endl;
fn(tutor); //怎么执行这条语句的,恳请把执行过程写清楚一点,我没搞懂。特别是s是谁的引用,我很糊涂。希望您能给予祥解:)
cout<<"returned from fn()"<<endl;
}

搜索更多相关主题的帖子: 函数 拷贝 
2006-02-08 11:55



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




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

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