• C++代码学习之一:组合模式例子


     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 } 
  • 相关阅读:
    简单的语句统计所有用户表尺寸大小
    CodeSmith 介绍
    Oracle Partition By 的使用
    Oracle Contact By的使用
    正则提取 html 里<input> 标记的value 值
    IOS 7 风格Checkbox
    aspose words 介绍
    大规模web 服务开发技术
    数学之美 读后感
    工作流简介--(转)
  • 原文地址:https://www.cnblogs.com/chip/p/3971732.html
Copyright © 2020-2023  润新知