Sah*_*has 2 c++ type-conversion
我正在尝试使用mingw在Windows上为gtkmm构建cairomm.编译在函数调用中断,该函数调用具有将bool的reinterpret_cast执行为void*的参数.
cairo_font_face_set_user_data(cobj(), &USER_DATA_KEY_DEFAULT_TEXT_TO_GLYPHS, reinterpret_cast<void*>(true), NULL);
Run Code Online (Sandbox Code Playgroud)
这是代码中断的地方,原因是"从bool到void*的reinterpret_cast无效".为什么会发生这种情况,如何修改此行以使其编译?需要帮忙
Jud*_*den 13
我看到这是用户数据,你可以控制对值的处理,首先将bool转换为int : reinterpret_cast<void *> (static_cast<int> (true)). 这样做有意义,因为void*参数取代了此ANSI-C库中的模板函数.您所需要的只是一个真/假值.因此,只要将其作为指针进行临时编码就不存在危险.真的,你最好reinterpret_cast<void *> (1)还是这样:或者reinterpret_cast<void *> (+true).