做交大作业时遇到的两个细节问题?

Alan S1 2003-10-18 12:46:53
本人是C++新手,请多赐教。原题地址:
1.在报刊定单类的构造函数中想直接输出实付金额,所以需在构造函数中调用成员函数。
但VC6.0报错。为问题简化期间我另编一个简化程序,望各路大侠指点迷津。
//构造函数中的成员函数.cpp
#include <iostream>
#include <string>
using namespace std;

class car{
private:
string name;
float speed;
float maxway;
float price;
public:
float payfactmaoney(float m){
m=price*0.8*speed*maxway;
return m;
}
car(float inispeed,float inimaxway,
float iniprice,string ininame) { }
}
car::car(string ininame,float inispeed,float inimaxway,
float iniprice) :name(ininame) speed(inispeed),
maxway(inimaxway),price(iniprice){
cout<<"请输入车的名称\n"; cin>>ininame;
cout<<"输入这车的车速\n"; cin>>inispeed;
cout<<"输入这车的最远路程\n"; cin>>inimaxway;
cout<<"这车的实际价格为:"
float f=payfactmaoney(float m);
cout<<f<<endl;
}

main()
{ car* c= new car ;//此行编译器说"unexpected end"
}

2.能否在派生类中调用基类的成员函数?我定义了一个单链表,让定单从它派生出来。其中
链表类中的成员Insert()是想让定单生成一个连接一个,所有的定单都组成一个链表。
newspaperorder<T>&newspaperorder<T>::Inset(const T&x){}
Insert()未在newspaperorder类中定义,Insert()也未在Linkedlist类中定义成viutual function.那定单还能生成一个连接一个吗?

由于时间关系,系统全部代码想以后再公开。本人先声明不是交大学子,是湖北经济学院的,洋洋洒洒上千行代码,感觉就象在写小说。希望在考研之前做点动东。否则真的学无所成了。
...全文
40 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
sms88 2003-10-18
  • 打赏
  • 举报
回复
能给我一份交大的习题吗?
sms91@163.com

2.派生类能够调用基类的公有和保护成员函数。
我认为应该可以调用Insert()函数。只要Insert()函数的参数有定义的类,并且返回相应的类
sms88 2003-10-18
  • 打赏
  • 举报
回复
你的类定义后面没有加上分号

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧