| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 720 人关注过本帖
标题:程序遇到问题!
只看楼主 加入收藏
cz522321
Rank: 1
等 级:禁止访问
威 望:2
帖 子:569
专家分:5
注 册:2006-3-13
结帖率:100%
收藏
 问题点数:0 回复次数:6 
程序遇到问题!
源程序如下:
#include<iostream.h>
class planet
{
protected:
//**1**
double distance;int revolve;
public:
planet(double d,int r)
{
distance=d;
revolve=r;
}
};
class Earth:public planet
{
double circumference;
public:
//**2**
Earth(double d,int r)
{
circumference=2*3.1416*d;
}
//**3**
void show()
{
cout<<"the circumference is"<<circumference<<endl;
cout<<"the distance is"<<distance<<endl;
cout<<"the revolve is"<<revolve<<endl;
}
};
void main()
{
Earth obj(9300000,365);
obj.show;
}

问题提示如下:
E:\我的文件\c++源文件\练习\prog4\prog4.cpp(19) : error C2512: 'planet' : no appropriate default constructor available
E:\我的文件\c++源文件\练习\prog4\prog4.cpp(34) : warning C4551: function call missing argument list
执行 cl.exe 时出错.
请帮忙解决一下。
搜索更多相关主题的帖子: distance include public double planet 
2006-09-23 10:07
lisypro
Rank: 4
等 级:业余侠客
威 望:3
帖 子:695
专家分:216
注 册:2005-9-25
收藏
得分:0 
obj.show;
应为obj.show();

长期承接管理系统
代做各种vb/ / vc小程序
QQ:82341763
手机:13623290828
群号 11619730
2006-09-23 11:40
cz522321
Rank: 1
等 级:禁止访问
威 望:2
帖 子:569
专家分:5
注 册:2006-3-13
收藏
得分:0 
那样改了之后还是有问题呀!没有解决!

2006-09-23 21:07
youngky
Rank: 1
等 级:新手上路
威 望:1
帖 子:75
专家分:0
注 册:2006-3-31
收藏
得分:0 
出现了外部问题

2006-09-24 22:00
flypampas
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2006-9-16
收藏
得分:0 

你的程序中的那个派生类没有显示的调用基类的构造函数。
当构造函数没有默认的构造函数又有别的构造函数时,派生类要显示的调用构造函数。
--------------------------------
你可以在基类中加一个默认的构造函数:
planet()
{
}
这样你输出的后两行将有错。
也可以在Earth(double d,int r)
上调用planet(double d,int r) 。
Earth(double d,int r):planet(d,r){函数体}。
#include<iostream.h>
class planet
{
protected:
//**1**
double distance;int revolve;
public:

planet(double d,int r)
{
distance=d;
revolve=r;
}
};
class Earth:public planet
{
double circumference;
public:
//**2**
Earth(double d,int r):planet(d,r)
{
circumference=2*3.1416*d;
}
//**3**
void show()
{
cout<<"the circumference is"<<circumference<<endl;
cout<<"the distance is"<<distance<<endl;
cout<<"the revolve is"<<revolve<<endl;
}
};
void main()
{
Earth obj(9300000,365);
obj.show();
}


java,c++...thinking......
2006-09-25 01:40
DEMON_HUNTER
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2006-3-10
收藏
得分:0 
如果基类定义了带有参数的构造函数时,派生类要定义构造函数,提供一个将参数传递给基类的途径,保证基类能正常初始化.

2006-09-25 18:20
cz522321
Rank: 1
等 级:禁止访问
威 望:2
帖 子:569
专家分:5
注 册:2006-3-13
收藏
得分:0 
谢谢两位了!

2006-09-26 22:17
快速回复:程序遇到问题!
数据加载中...
 
   



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

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