#include <iostream>using namespace std;class mannal{ mannal():itsage(1) {cout<<"mannal con"<<endl;} virtual ~mannal() {cout<<"mannal de"<<endl;} mannal(const mannal & rhs); virtual void speak() const {cout<<"mannal speak"<<endl;} virtual mannal* clone(){return new mannal(*this);} int getage() const {return itsage;}protected: int itsage;};mannal::mannal(const mannal & rhs):itsage(rhs.getage()){ cout<<"mannal copy con"<<endl;}class dog: public mannal{public: dog() {cout<<"dog con"<<endl;} virtual ~dog() {cout<<"dog de"<<endl;} dog (const dog & rhs); void speak() const {cout<<"dog speak"<<endl;} virtual mannal* clone(){return new dog(*this);}};dog::dog(const dog & rhs):mannal(rhs){ cout<<"dog copy con"<<endl;}class cat: public mannal{public: cat(){cout<<"cat con"<<endl;} virtual ~cat(){cout<<"cat de"<<endl;} cat(const cat &rhs); void speak() const {cout<<"cat speak"<<endl;} virtual mannal* clone(){return cat(*this);}};cat::cat(const cat & rhs):mannal(rhs){ cout<<"cat copy con"<<endl;}enum animals{ mannal,dog,cat};const int num=3;int main(){ mannal *a[num]; mannl* ptr; int choice,i; for(i=0;i<num;i++) { cout<<"dag cat mannal:"; cin>>choice; switch(choice) { case dog: ptr=new dog; break; case cat: ptr=new cat; break; default: ptr=new mannal; break; } a[i]=ptr; } mannal *t[num]; for(i=0;i<num;i++) { a[i]->speak(); t[i]=a[i]->clone(); } for(i=0;i<num;i++) t[i]->speak(); return 0;}
引用第5楼空中战机于2007-12-04 11:03发表的 :我是用VC看的 很多错误 不过都是在一处 但是我不知道怎么改 VC的提示我不知道怎么改正啊
VC提示错误是在 break; } a=ptr;这里 在"{"前少了";" 我看不懂啊 那里好像是正确的啊