Visual C++ 확장기능: 클래스 속성 만들기

c#에 보면 property란게 있어서 코딩시에 변수처럼 사용하면서 값을 대입하거나 가져올때의 동작을 작성할 수가 있다.
이런 property는 vc++에서도 확장기능으로 지원한다... 상당히 예전부터 지원하던거라 새로운 내용은 아니다..

msdn에 의한 스펙을 보면 다음과 같다.

__declspec( property( get=get_func_name ) ) declarator
__declspec( property( put=put_func_name ) ) declarator
__declspec( property( get=get_func_name, put=put_func_name ) ) declarator

클래스 선언안에 위와 같은 형식으로 적으면 되는데, property() 의 괄호안에 get항목만 적으면 읽기전용 속성이 되는것이고
put항목만 적으면 쓰기전용, get,put둘다 적으면 읽기,쓰기가 다 되는 속성을 만드는 것이다.














msdn에 있는 예제

// declspec_property.cpp
struct S {
   int i;
   void putprop(int j) {
      i = j;
   }

   int getprop() {
      return i;
   }

   __declspec(property(get = getprop, put = putprop)) int the_prop;
};

int main() {
   S s;
   s.the_prop = 5;
   return s.the_prop;
}

by kiho | 2007/12/19 15:57 | 프로그래밍 팁 | 트랙백 | 덧글(1)

트랙백 주소 : http://kiho.egloos.com/tb/4019539
☞ 내 이글루에 이 글과 관련된 글 쓰기 (트랙백 보내기) [도움말]
Commented by 알디 at 2008/02/23 04:58
VC 종속되니까 독립적으로 짤려면 쓰면 곤란하겠다.

:         :

:

비공개 덧글

◀ 이전 페이지          다음 페이지 ▶