zoukankan      html  css  js  c++  java
  • 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 } 
  • 相关阅读:
    自动登录网站
    爬取梨视频
    爬虫介绍,request模块和代理ip
    数据结构与算法
    CMDB的总结
    自动化运维模块
    linux命令补充
    centos7的目录结构,文件系统常用的命令,vim编辑器
    linux配置网卡文件,xshell链接服务,快照,克隆,修改主机名
    flask的请求扩展,错误处理,标签和过滤器,中间件以及cbv的写法
  • 原文地址:https://www.cnblogs.com/chip/p/3971732.html
Copyright © 2011-2022 走看看