C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[10314] Re:멤버함수 포인터를 일반함수 포인터로 형 변환이 가능할까요?
이창환 [catchv] 1489 읽음    2001-08-27 13:45
그냥 참고 하세여....(저도 초심자라서...^^;)

C++ Builder에는 __closure라는 것이 있더군여...

이걸 써 보세여...

하여튼 예를 만들어 보았습니다.

설명은 밑에 도움말을 캡쳐해서 올립니다..(좋은 내용 같음....ㅠㅠ)

__closure

The __closure keyword is used to declare a special type of pointer to a member function. Unlike a regular C++ member function pointer, a closure contains an object pointer.
In standard C++, you can assign a derived class instance to a base class pointer; however, you cannot assign a derived class뭩 member function to a base class member function pointer. The following code illustrates this:

class base

{
  public:
    void func(int x);
};

class derived: public base

{
  public:
    void new_func(int i);
};

void (base::*bptr)(int);

bptr = &derived::new_func;    // illegal

However, the __closure language extension allows you to do this in C++Builder. A closure associates a pointer to a member function with a pointer to a class instance. The pointer to the class instance is used as the this pointer when calling the associated member function. A closure declaration is the same as a function pointer declaration but with the addition of the __closure keyword before the identifier being defined. For example:

struct MyObject

{
  double MemFunc(int);
};

double func1(MyObject *obj)

{
  // A closure taking an int argument and returning double.
  double ( __closure *myClosure )(int);

  // Initialize the closure.

  myClosure = obj -> MemFunc;

  // Use the closure to call the member function and pass it an int.

  return myClosure(1);
}

Although the preceding discussion illustrates closures by assigning descendant class methods, you can assign any class method pointer to a closure. That is, closures allow completely disparate classes to share a method pointer.
Closures are used with events in C++Builder.

+ -

관련 글 리스트
10306 멤버함수 포인터를 일반함수 포인터로 형 변환이 가능할까요? 김준한 1954 2001/08/26
10314     Re:멤버함수 포인터를 일반함수 포인터로 형 변환이 가능할까요? 이창환 1489 2001/08/27
10320         Re:Re:오~~ 놀라워라 이런기능이 ... 창환이 많이 컷구나~~~ 최보현.U&I 1454 2001/08/27
10307     Re:멤버함수 포인터를 일반함수 포인터로 형 변환이 가능할까요? 최보현.U&I 2204 2001/08/26
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.