How can I write a C++ type conversion operator to implicitly convert all void* to MyStruct* -
i'm learning windows driver dev, , find problem using visualddkhelper.h c++ code(no problem c code).
the question boils down this:
// --- formal windows driver sdk header --- typedef void * handle; // --- visualddkhelper.h --- class handle_visualddk_helper { }; typedef handle_visualddk_helper *handle_visualddk_helper_t; #define handle handle_visualddk_helper_t // ★ visualddk handle tweaker // --- user code --- void foo(handle s) { } //operator smy*()(void* ptr) { return (smy*)ptr; } // how can write type conversion operator user code compiles ok. int main() { char* s = "abc"; class user_struct1 { int m; } *pu1 = 0; class user_struct2 { int m; } *pu2 = 0; foo(s); foo(pu1); foo(pu2); // lots of these return 0; }
i'm unwilling convert driver code like:
foo((handle)s); foo((handle)pu1); foo((handle)pu2); // lots of these
can c++ operator overloading me out?
Comments
Post a Comment