1 #include"AbstractFile.h" void AbstractFile::add(AbstractFile*) 2 { 3 } void AbstractFile::remove() 4 { 5 } void AbstractFile::display() 6 { 7 } #include"Folder.h" 8 folder::folder(string filename) 9 { 10 this->filename=filename; 11 } void folder::remove() 12 { 13 } void folder::add(AbstractFile *p) 14 { 15 m_vAbstractfile.push_back(p); 16 } void folder::display() 17 { 18 cout<<"+"<<filename<<endl; 19 vector<AbstractFile*>::iterator it=m_vAbstractfile.begin(); 20 for(;it!=m_vAbstractfile.end();++it) 21 { 22 (*it)->display(); 23 } 24 } 25 #include"imagefile.h" 26 void imagefile::add(AbstractFile* p) 27 { 28 } 29 imagefile::imagefile(string filename) 30 { 31 this->filename=filename; 32 } void imagefile::remove() 33 { 34 } void imagefile::display() 35 { 36 cout<<"图片输出 "<<this->filename<<endl; 37 } 38 #include"videofile.h" 39 videofile::videofile(string filename) 40 { 41 this->filename=filename; 42 } void videofile::add(AbstractFile* p) 43 { 44 } void videofile::remove() 45 { 46 } void videofile::display() 47 { 48 cout<<"影像输出"<<this->filename<<endl; 49 } 50 #include<stdio.h> 51 #include"AbstractFile.h" 52 #include"Folder.h" 53 #include"imagefile.h" 54 #include"videofile.h" int main() 55 { 56 AbstractFile *p=new folder("folder"),*p3,*p2,*p4; 57 folder *p1; 58 p3=new imagefile("imagefile"); 59 p2=new videofile("vediofile"); 60 p4=new imagefile("imagefile2"); 61 p1=new folder("folder1"); 62 p->add(p3); 63 p->add(p2); 64 65 p1->add(p4); 66 p->add(p1); 67 p->display(); 68 69 return 0; 70 }
时间: 2024-09-30 20:55:24