文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>[创建型模式] Prototype

[创建型模式] Prototype

时间:2011-03-10  来源:Cheney Shen

Prototype.h

//
//  Prototype.h
//  Prototype
//
//  Created by Cheney Shen on 11-2-20.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#ifndef _PROTOTYPE_H_
#define _PROTOTYPE_H_

class Prototype
{
    public:
    virtual ~Prototype();
    virtual Prototype* Clone() const = 0;
    
    protected:
    Prototype();
    
    private:
    
};

class ConcretePrototype:public Prototype
{
    public:
    ConcretePrototype();
    ConcretePrototype(const ConcretePrototype& cp);
    ~ConcretePrototype();
    Prototype* Clone() const;
    
    protected:
    
    private:
    
};

#endif  //~_PROTOTYPE_H_

Prototype.cpp

//
//  Prototype.cpp
//  Prototype
//
//  Created by Cheney Shen on 11-2-20.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#include "Prototype.h"
#include <iostream>
using namespace std;

Prototype::Prototype()
{
    
}

Prototype::~Prototype()
{
    
}

Prototype* Prototype::Clone() const
{
    return 0;
}

ConcretePrototype::ConcretePrototype()
{
    
}

ConcretePrototype::~ConcretePrototype()
{
    
}

ConcretePrototype::ConcretePrototype(const ConcretePrototype& cp)
{
    cout<<"ConcretePrototype copy..."<<endl;
}

Prototype* ConcretePrototype::Clone() const
{
    return new ConcretePrototype(*this);
}

main.cpp

//
//  main.cpp
//  Prototype
//
//  Created by Cheney Shen on 11-2-20.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//
#include "Prototype.h"
#include <iostream>
using namespace std;

int main (int argc, const char * argv[]) {

    Prototype* p = new ConcretePrototype();
    Prototype* p1 = p->Clone();
    delete p1;
    p1 = NULL;
    return 0;
}
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载