继续关于C++中接口的一些认识
上次发贴问了一下关于接口的的问题,有幸得到版主的回答,很是兴奋。
在经过我一段时间思考觉得如下解释可能会好一点
class bulb { public: virtual void on()=0; virtual void off()=0; }; class white_bulb :public bulb { public: void on(){cout<<"from class white_bulb::on() \n";} void off(){cout<<"from class y::off()\n";} };class other_bulb :public bulb { public: void on(){cout<<"from class other_bulb::on() \n";} void off(){cout<<"from class other_bulb::off()\n";} }; void use_bulb(bulb &s) { s.on(); } int main(int argc, char *argv[]){ other_bulb o_bulbs; use_bulb(o_bulbs); system("PAUSE"); return 0;}interface bulb{ void on(); void off();}