标题:又是关于类的。
取消只看楼主
XIAO荣
Rank: 2
等 级:论坛游民
帖 子:87
专家分:20
注 册:2009-2-26
结帖率:100%
已结贴  问题点数:20 回复次数:4 
又是关于类的。
请帮忙解释下注释的那一条语句,就一条,非常感谢 。
单冒号的作用...

#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 编辑 ]
搜索更多相关主题的帖子: 类的定义 
2009-08-17 16:17
XIAO荣
Rank: 2
等 级:论坛游民
帖 子:87
专家分:20
注 册:2009-2-26
得分:0 
Price(char ff[],char tt[],int mm,int pp):Station(ff,tt),Mile(mm)
冒号的作用是不是构造函数给后面的Station(ff,tt)和Mile(mm)赋值?
2009-08-17 16:23
XIAO荣
Rank: 2
等 级:论坛游民
帖 子:87
专家分:20
注 册:2009-2-26
得分:0 
回复 3楼 jd205

请问,是冒号前面的东西对冒号后面的进行初始化,还是后面的对前面的进行初始化?
这程序,Mile好象和Station是两个不同的类吧,之间应该没什么关系吧?
2009-08-17 17:08
XIAO荣
Rank: 2
等 级:论坛游民
帖 子:87
专家分:20
注 册:2009-2-26
得分:0 
有高手帮忙解答一下么??

[ 本帖最后由 XIAO荣 于 2009-8-18 10:55 编辑 ]
2009-08-18 10:39
XIAO荣
Rank: 2
等 级:论坛游民
帖 子:87
专家分:20
注 册:2009-2-26
得分:0 
回复 7楼 pangding

懂了,谢谢喔。
2009-08-20 10:56



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




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

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