又是关于类的。
请帮忙解释下注释的那一条语句,就一条,非常感谢 。单冒号的作用...
#include<iostream.h>
#include<string.h>
const int LEN=50;
class Station
{
protected:
char from_station[LEN];
char to_station[LEN];
public:
Station(char fs[],char ts[])
{
strcpy(from_station,fs);
strcpy(to_station,ts);
}
void input_value()
{
cout<<"Enter from station:"<<endl;
cin>>from_station;
cout<<"Enter to station:"<<endl;
cin>>to_station;
}
void display()
{
cout<<"Going from "<<from_station<<"station to "<<to_station<<" station";
}
};
class Mile
{
protected:
int mile;
public:
Mile(int m)
{
mile=m;
}
void input_mile()
{
cout<<"Enter mile:";
cin>>mile;
}
void display()
{
cout<<" is"<<mile<<" miles";
}
};
class Price:public Station,public Mile
{
int price;
public:
Price(char ff[],char tt[],int mm,int pp):Station(ff,tt),Mile(mm)//就是这里,中间的冒号起什么作用?这类型的定义是什么格式来的?
{
price=pp;
}
void getprice()
{
Station::input_value();
Mile::input_mile();
cout<<"Enter price:";
cin>>price;
}
void display()
{
Station::display();
Mile::display();
cout<<" The price is "<<price<<endl;
}
};
void main()
{
Price A("Beijing","Xia men",1400,50);
A.display();
}
[ 本帖最后由 XIAO荣 于 2009-8-17 16:19 编辑 ]