I need to implement similar mechanism like @selector(Objecitive-C) in C++. By googling i have found. It does not help me...
template <class AnyClass>
class ClassCallback
{
// pointer to member function
void (AnyClass::*function)(void);
// pointer to object
AnyClass object;
public:
ClassCallback() { }
~ClassCallback() { }
ClassCallback(AnyClass _object, void(AnyClass::*_function)(void))
: object( _object ), function( _function ) { };
virtual void call(){
(object->*function)();
};
};
Is there any different approach to implement which is similar to objective-C like
typedef struct objc_selector *MY_SEL;
Need to implement objc_selector It is abstract class in objective-C. How to implement objc_selector any idea...
Just a few precisions on the Objective-C messaging system, with the selectors.
A selector (SEL) is an opaque type, but it's only something like a char *, containing only the name of the method (so many classes can share the same selector).
An Obj-C method is a struct containing:
SEL fieldchar * containing infos about the return type and arguments.IMP fieldSomething like:
struct objc_method
{
SEL method_name;
char * method_types;
IMP method_imp;
};
typedef objc_method Method;
An IMP is just a C function pointer.
Objective-C and C++ are very different languages, and as far as I know C++ doesn't have anything equivalent or even similar to Objective-C's selectors. If you explain the problem you're trying to solve, I'm sure someone here will be happy to discuss the way that problem might be dealt with from a C++ perspective.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With