标题:包含不同类型参数的构造函数
取消只看楼主
meweiwei
Rank: 1
来 自:广东省茂名市
等 级:新手上路
帖 子:42
专家分:0
注 册:2007-5-15
 问题点数:0 回复次数:1 
包含不同类型参数的构造函数

请教各位大侠:一个构造函数是否允许包含不同类型的参数,如果允许的,又怎么定义这个构造函数?
#include <iostream>
using namespace std;
class Day
{
private:
int year,month,day;
public:
Day(int y,int m,int d)
{ year=y; month=m; day=d ; }
Day (Day &one)
{ year =one.year; month=one.month; day=one.day; }
void show()
{ cout<<year<<' '<<month<<' '<<day<<endl;}

};
class person
{
private:
int num,IDnum;
char sex;
Day birthday;
public:
person(int n,int IDn ,char s,Day &birthday);

};
int main()
{

return 0;
}

搜索更多相关主题的帖子: 函数 构造 参数 类型 
2007-05-15 17:56
meweiwei
Rank: 1
来 自:广东省茂名市
等 级:新手上路
帖 子:42
专家分:0
注 册:2007-5-15
得分:0 

谢谢两位.
不过我还是出了一个错:
error C2512: 'Day' : no appropriate default constructor available
怎么改啊?
#include <iostream>
using namespace std;
class Day
{
private:
int year,month,day;
public:
Day(int y,int m,int d)
{ year=y; month=m; day=d ; }
Day (Day &one)
{ year =one.year; month=one.month; day=one.day; }
void show()
{ cout<<year<<' '<<month<<' '<<day<<endl;}

};
class person
{
private:
int num,IDnum;
char sex;
Day birthday;
public:
person(int n ,int IDn)
{ num=n; IDnum=IDn; }

person( char s)
{ sex=s;}
person( Day &bir)
{ birthday= bir;}
void show ()
{ cout<<num<<' '<<IDnum<<' '<<sex<<endl; }


};
int main()
{

return 0;
}

2007-05-15 18:30



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




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

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