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
[52501] 클래스의 멤버 함수 포인터를 void * 로 형변환하는 간단한 방법?
[] 2448 읽음    2008-03-03 11:32
클래스의 멤버 함수 포인터를 void* 로 형변환하는 방법 중 아래 4 가지와 같이 변수를 통하지 않고
바로 형변환하는 방법이 없을까요?

class TTestClass
{
public:
int Method1(int a,int b,int c)const
{
    return (a+b+c);
}
};  

방법1:
typedef void (TTestClass::*FuncType)();
FuncType func = (FuncType)&TTestClass::Method1;
*(void**)&func

방법2:
void (TTestClass::*func)() = (void (TTestClass::*)())&TTestClass::Method1;
*(void**)&func

방법3:
union Func2Pointer
{
  void (TTestClass::*Func)();
  void *VoidPointer;
}fp;
fp.Func = (void (TTestClass::*)())&TTestClass::Method1;
fp.VoidPointer

방법4:
typedef int (__closure *ClosureType)(int a,int b,int c);
union Closure2Pointer
{
  ClosureType Closure;
  struct{
   void *VoidPointer;
   void *This;
  };
}cp;
TTestClass c1;
cp.Closure = c1.Method1;
cp.VoidPointer

+ -

관련 글 리스트
52501 클래스의 멤버 함수 포인터를 void * 로 형변환하는 간단한 방법? 2448 2008/03/03
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.