오후 2:48 2003-08-06
조경민 bro@shinbiro.com
VC++에서 제공하는 property를 에뮬레이트
=======================================================================

typedef struct tagMyStruct
{
   __declspec(property(get=GetValue1, put=PutValue1))

   long  m_lValue1;
   ...                // Rest of the structure definition.

   long GetValue1()
   {
      return m_lInternalValue1;
   }

   void PutValue1(long lValue)
   {
      m_lInternalValue = lValue;
   }

private:
        long m_lInternalValue1;

        // Define critical section member variable.
} SMyStruct;


아래와 같이 에뮬가능하다.

template <class T>
class _prop
{
        T        _t;
public:
        _prop(){}
        _prop( const T& t ) { set(t); }
        T& operator = ( const T& t ) { return set(t); }
        operator T() { return get(); }

        T& set( const T& t ) { _t = t; return _t; }
        T& get() { return _T; }
};

struct Student
{
        _prop< DWORD >                        age;
        _prop< CString >                name;
};


        Student bro;
        bro.age = 30;
        bro.name = _T("bro");

        TRACE(_T("%d %s"), bro.age, bro.name );

'KB > MFC/Win32' 카테고리의 다른 글

동적으로 생성된 컨트롤이 메시지를 받지 못할때  (0) 2004.04.28
다이얼로그 팁  (0) 2004.04.28
msn6 코드 스니펫  (0) 2004.03.19
MSN 코드 모음  (0) 2004.03.19
mshtml 메모리 릭 최소화하기  (0) 2004.03.19

+ Recent posts