| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 660 人关注过本帖
标题:构造函数问题
取消只看楼主 加入收藏
vic_space
Rank: 1
等 级:新手上路
帖 子:38
专家分:0
注 册:2006-5-24
收藏
 问题点数:0 回复次数:0 
构造函数问题

请看下面程序2种写法,一个是构造函数在类里面,一个在外面~!怎么只能在类里面的才通过编译~!
class Desk

{
private:
int weight;
int height;
int width;
int length;
public:
Desk(int,int,int,int);

};

Desk::Desk(int we=3,int h=4,int wi=5,int l=6)
{
weight=we;
height=h;
width=wi;
length=l;
cout<<weight<<height<<width<<length<<endl;
}


void main()
{
Desk dk1;
Desk dk2(6,5);
Desk dk3(6,5,5,5);
cout<<"Back in main"<<endl;
}

======================================================================
class Desk

{
private:
int weight;
int height;
int width;
int length;
public:
Desk(int we=3,int h=4,int wi=5,int l=6)
{
weight=we;
height=h;
width=wi;
length=l;
cout<<weight<<height<<width<<length<<endl;
}

};

void main()
{
Desk dk1;
Desk dk2(6,5);
Desk dk3(6,5,5,5);
cout<<"Back in main"<<endl;
}
===================================================================
问题是在Desk dk1;这个对象定义不能读取默认值~!

搜索更多相关主题的帖子: 函数 构造 
2006-09-18 22:00
快速回复:构造函数问题
数据加载中...
 
   



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

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