336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

** CClock.h
#ifndef __CCLOCK_H_
#define  __CCLOCK_H_
#include 

using namespace std;
class CClock
{
public:
  virtual void Draw() = 0;
};

class CAnalogClock : public CClock
{
public:
  virtual void Draw()
  {
    cout << "아날로그 시계를 그린다." << endl;
  }
};

class CDigitalClock : public CClock
{
public:
  virtual void Draw()
  {
    cout << "디지털 시계를 그린다." << endl;
  }
};
#endif

** CClockDateDecorator.h
#ifndef __CCLOCK_DATE_DECORATOR_H_
#define __CCLOCK_DATE_DECORATOR_H_
#include 
#include "CClock.h"

using namespace std;

class CClockDateDecorator : public CClock
{
public:
  virtual void Draw();

public:
  CClockDateDecorator (CClock* a_pClock)
    : m_pClock(a_pClock)
  {

  }

  virtual ~CClockDateDecorator()
  {
    if (m_pClock)
      delete m_pClock;
  }

private:
  CClock* m_pClock;
};

void CClockDateDecorator::Draw()
{
  m_pClock->Draw();

  cout << "날짜를 그린다" << endl;
}

class CWorldDecorator : public CClock
{
public:
  virtual void Draw();

public:
  CWorldDecorator (CClock* a_pClock, char* a_szCity)
    : m_pClock(a_pClock)
  {
    m_pCity = new char [strlen(a_szCity) + 1];
    strcpy(m_pCity, a_szCity);
  }

  virtual ~CWorldDecorator()
  {
    if (m_pClock)
      delete m_pClock;

    if (m_pCity)
      delete m_pCity;
  }

private:
  CClock* m_pClock;
  char* m_pCity;
};

void CWorldDecorator::Draw()
{
  m_pClock->Draw();

  cout << m_pCity <<" 도시의 시간 표시를 한다" << endl;
}

#endif

** main.cpp
  CClock* pDataClock = new CClockDateDecorator (new CAnalogClock);
  //pDataClock->Draw();

  CClock* pWorldClock = new CWorldDecorator (pDataClock, "seoul");
  pWorldClock->Draw();

  delete pDataClock;
  delete pWorldClock;
블로그 이미지

뚱땡이 우주인

,