1#include"AbstractFile.h" voidAbstractfile::add (abstractfile*) 2 { 3}voidAbstractfile::remove ()4 { 5}voidabstractfile::d isplay ()6 { 7} #include"Folder.h" 8Folder::folder (stringfilename)9 { Ten This->filename=filename; One}voidFolder::remove () A { -}voidFolder::add (Abstractfile *p) - { the M_vabstractfile.push_back (p); -}voidfolder::d isplay () - { -cout<<"+"<<filename<<Endl; +Vector<abstractfile*>::iterator it=M_vabstractfile.begin (); - for(; It!=m_vabstractfile.end (); + +it) + { A(*it)display (); at } - } -#include"imagefile.h" - voidImagefile::add (abstractfile*p) - { - } inImagefile::imagefile (stringfilename) - { to This->filename=filename; +}voidImagefile::remove () - { the}voidimagefile::d isplay () * { $cout<<"Picture Output"<< This->filename<<Endl;Panax Notoginseng } -#include"videofile.h" theVideofile::videofile (stringfilename) + { A This->filename=filename; the}voidVideofile::add (abstractfile*p) + { -}voidVideofile::remove () $ { $}voidvideofile::d isplay () - { -cout<<"Image Output"<< This->filename<<Endl; the } -#include <stdio.h>Wuyi#include"AbstractFile.h" the#include"Folder.h" -#include"imagefile.h" Wu#include"videofile.h" intMain () - { AboutAbstractfile *p=NewFolder"folder"), *p3,*p2,*P4; $Folder *P1; -p3=NewImageFile ("ImageFile"); -P2=NewVideofile ("Vediofile"); -p4=NewImageFile ("Imagefile2"); Ap1=NewFolder"Folder1"); +P->Add (p3); theP->Add (p2); - $P1->Add (p4); theP->Add (p1); theP->display (); the the return 0; -}
One of the C + + code learning: Combinatorial Pattern examples