| 发表于:2007-08-31 15:08:52 楼主 |
#include <iostream> class vehicle { public: vehicle(float speed,int total): { vehicle::speed=speed; //搞不懂这里为什么要加上vehicle:: vehicle::total=total; //搞不懂这里为什么要加上vehicle:: } virtual void showmember() { cout < <speed < < " ¦ " < <total < <endl; } virtual ~vehicle() { cout < < "载入vehicle基类析构函数 " < <endl; cin.get(); } protected: float speed; int total; }; class car:public vehicle { public: car(int aird,float speed,int total): vehicle(speed,total) { car::aird=aird; //搞不懂这里为什么要加上car:: } virtual void showmember() { cout < <speed < < " ¦ " < <total < < " ¦ " < <aird < <endl; } virtual ~car() { cout < < "载入car派生类析构函数 " < <endl; cin.get(); } protected: int aird; }; void test(vehicle &temp) { temp.showmember(); } void main() { vehicle a(120,4); car b(180,110,4); test(a); test(b); cin.get(); } 如果把里面的**::输出的东东就会有错...谢谢高手指点... |
|
|
|
|