| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 482 人关注过本帖
标题:关于默认拷贝函数
只看楼主 加入收藏
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
快速回复:关于默认拷贝函数
数据加载中...
 
   



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

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