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

#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
woodhead
Rank: 3Rank: 3
等 级:新手上路
威 望:9
帖 子:1124
专家分:0
注 册:2005-7-18
得分:0 
?
不就是调用void fn(Tutor),把tutor作为参数传递给函数么

2006-02-08 14:10



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




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

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