:: :: 博问 :: 闪存 :: :: 联系 :: :: 管理 ::
#pragma once

class CAnimal
{
public:
    
~CAnimal(void);
    
virtual CAnimal* Create() const = 0;
    
virtual void SayHello(void);
};

#include 
"StdAfx.h"
#include 
".\animal.h"


CAnimal::
~CAnimal(void)
{
}

void CAnimal::SayHello(void)
{
    std::cout 
<< "hello CAnimal" << std::endl;
}
/////////////////////////////////////////////
#pragma once
#include 
"animal.h"

class CCat :
    
public CAnimal
{
public:
    CCat
* Create() const;
    
~CCat(void);
    
virtual void SayHello(void);
};

#include 
"StdAfx.h"
#include 
".\cat.h"

CCat 
* CCat::Create() const
{
    
return new CCat();
}

CCat::
~CCat(void)
{
}

void CCat::SayHello(void)
{
    std::cout 
<< "Hello CCat" << std::endl;
}
////////////////////////////////////////////

 

#pragma once
#include 
"animal.h"

class CDog :
    
public CAnimal
{
public:
    
~CDog(void);

    CDog
* Create() const;

    
virtual void SayHello(void);
};

#include 
"StdAfx.h"
#include 
".\dog.h"

CDog::
~CDog(void)
{
}

CDog
* CDog::Create() const
{
    
return new CDog();
}

void CDog::SayHello(void)
{
    std::cout 
<< "Hello CDog" << std::endl;
}
///////////////////////////////////////////////

 

 

#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{
    std::vector
<CAnimal*> Vector_Animal;
    Vector_Animal.push_back(
new CDog());
    Vector_Animal.push_back(
new CCat());
    
    for_each(Vector_Animal.begin(), Vector_Animal.end(), std::mem_fun(
&CAnimal::SayHello));

    
return 0;
}

 

#pragma once


#include 
<iostream>
#include 
<tchar.h>

// TODO: 在此处引用程序要求的附加头文件
#include <string>
#include 
<vector>
#include 
<algorithm>
#include 
<functional>

#include 
"Animal.h"
#include 
"Dog.h"
#include 
"Cat.h"

 

 

posted on 2006-03-25 13:25  dtor  阅读(382)  评论(0编辑  收藏  举报