|
그냥 참고 하세여....(저도 초심자라서...^^;)
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.
|