Method functions are just functions that take a pointer to the object in the first argument representing 'this', there's nothing more special about them than that. As long as the primitive types match, it will work.
On Monday, April 10, 2017 at 1:15:27 PM UTC-7, Alon Zakai wrote: > > In general, casting (MenuItem*)() to (Object*)() would be safe, as the > single argument in the function type is a pointer, and while the pointers > are different, all pointers are just 32-bit integers. So this would just > work. > > However, here you have pointers to class methods, so the class matters > too. I don't remember how method pointers work, so I'm not sure. However, > this could be ok, since there is just an extra 'this' pointer basically, > and that is again just another 32-bit integer. Unless I am forgetting > something here. > > > On Wed, Apr 5, 2017 at 9:38 PM, Александр Гурьянов <[email protected] > <javascript:>> wrote: > >> For example I have class hierarchy: >> Object <- MyObject >> Object <- MenuItem >> >> class MyObject: public Object { >> void handler(MenuItem* item); >> } >> >> Is it safe to cast void(MyObject::*)(MenuItem*) to >> void(Object::*)(Object*)? Or I should use MULATE_FUNCTION_POINTER_CASTS=1 >> in this case too? >> >> I thinking about replacing static_cast<> with less strict check: >> >> template <typename R, typename O, typename ... Types> >> cocos2d::SEL_MenuHandler menu_selector(R(O::*f)(Types ...)) { >> static_assert(std::is_same<std::integral_constant<int, sizeof >> ...(Types)>, std::integral_constant<int, 1>>::value, >> "menu_selector should accept one argument - CCObject*"); >> return (cocos2d::SEL_MenuHandler) f; >> } >> >> The idea of this code is to check argument count of menu handler >> function, and if it matches - cast it. Is it safe? >> >> -- >> You received this message because you are subscribed to the Google Groups >> "emscripten-discuss" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > > -- You received this message because you are subscribed to the Google Groups "emscripten-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
