注册 登录
编程论坛 C++教室

C++ 多态继承 求解释

yanchina 发布于 2014-07-03 10:00, 403 次点击
程序代码:
#include <string.h>
#include<iostream>
using namespace std;

enum note{middleC,Csharp,Cflat};//删掉就不能通过


class instrument{
public:
    void play(note) const{
        cout<<"instrument::play"<<endl;
    }
};
class wind:public instrument{
    void play(note)const{
        cout<<"wind::play"<<endl;
    }
};
void tune(instrument& i){
    i.play(middleC);
}
int main()
{
    //wind flute;
    wind(flute); //这么定义为什么能通过???

    tune(flute);
    system("pause");
    return 0;
}

2 回复
#2
funyh2502014-07-03 13:23
创建类的对象要调用其构造函数
你都研究到多态了,这个应该懂吧
#3
rjsp2014-07-03 14:46
wind(flute); //这么定义为什么能通过???
--- 语法是人为规定的,wind(flute) 就是定义了一个类型为wind的变量flute
1