rttrorg / rttr

C++ Reflection Library
https://www.rttr.org
MIT License
3.2k stars 444 forks source link

get_by_name failed #375

Closed Magicsong111 closed 4 months ago

Magicsong111 commented 4 months ago

I'm trying to use rttr::get_by_name to get types. But there are some errors: In file included from D:/mingw64/x86_64-w64-mingw32/include/rttr/registration.h:821, from D:/mingw64/x86_64-w64-mingw32/include/rttr/registration:46, from C:\Users\Administrator\Documents\C++\Tests\easyclang.cpp:1: D:/mingw64/x86_64-w64-mingw32/include/rttr/detail/registration/registration_impl.h: In instantiation of 'static rttr::registration::bind<rttr::detail::prop_readonly, rttr::detail::invalid_type, A, rttr::detail::public_access, Visitor_List> rttr::registration::property_readonly(rttr::string_view, A) [with A = int; Visitor_List = rttr::type_list<>; rttr::string_view = rttr::basic_string_view]':
C:\Users\Administrator\Documents\C++\Tests\easyclang.cpp:20:36: required from here D:/mingw64/x86_64-w64-mingw32/include/rttr/detail/registration/registration_impl.h:248:45: error: static assertion failed: No valid property accessor provided! 248 | static_assert(std::is_pointer::value || is_functor::value, | ~~^~~~~~~ D:/mingw64/x86_64-w64-mingw32/include/rttr/detail/registration/registration_impl.h:248:45: note: '(((bool)std::integral_constant<bool, false>::value) || ((bool)std::integral_constant<bool, false>::value))' evaluates to false In file included from D:/mingw64/x86_64-w64-mingw32/include/rttr/detail/constructor/constructor_wrapper.h:33, from D:/mingw64/x86_64-w64-mingw32/include/rttr/detail/registration/registration_impl.h:33, from D:/mingw64/x86_64-w64-mingw32/include/rttr/registration.h:821, from D:/mingw64/x86_64-w64-mingw32/include/rttr/registration:46, from C:\Users\Administrator\Documents\C++\Tests\easyclang.cpp:1: D:/mingw64/x86_64-w64-mingw32/include/rttr/detail/type/accessor_type.h: In instantiation of 'struct rttr::detail::property_type': D:/mingw64/x86_64-w64-mingw32/include/rttr/detail/registration/bind_impl.h:548:19: required from 'static std::unique_ptr rttr::registration::bind<rttr::detail::prop_readonly, Class_Type, A, acc_level, Visitor_List>::create_default_property(rttr::string_view, Acc) [with Acc = int; Class_Type = rttr::detail::invalid_type; A = int; acc_level = rttr::detail::public_access; Visitor_List = rttr::type_list<>; rttr::string_view = rttr::basic_string_view]' D:/mingw64/x86_64-w64-mingw32/include/rttr/detail/registration/bind_impl.h:596:49: required from 'rttr::registration::bind<rttr::detail::prop_readonly, Class_Type, A, acc_level, Visitor_List>::~bind() [with Class_Type = rttr::detail::invalid_type; A = int; acc_level = rttr::detail::public_access; Visitor_List = rttr::type_list<>]' C:\Users\Administrator\Documents\C++\Tests\easyclang.cpp:20:36: required from here D:/mingw64/x86_64-w64-mingw32/include/rttr/detail/type/accessor_type.h:64:12: error: invalid use of
rttr::detail::conditional_t<false, rttr::detail::member_func_ptr, void>' {aka 'void'} 64 | struct property_type : conditional_t< std::is_member_function_pointer::value, | ^~~~~ In file included from D:/mingw64/x86_64-w64-mingw32/include/rttr/detail/registration/registration_impl.h:43, from D:/mingw64/x86_64-w64-mingw32/include/rttr/registration.h:821, from D:/mingw64/x86_64-w64-mingw32/include/rttr/registration:46, from C:\Users\Administrator\Documents\C++\Tests\easyclang.cpp:1: D:/mingw64/x86_64-w64-mingw32/include/rttr/detail/registration/bind_impl.h: In instantiation of 'static std::unique_ptr rttr::registration::bind<rttr::detail::prop_readonly, Class_Type, A, acc_level, Visitor_List>::create_default_property(rttr::string_view, Acc) [with Acc = int; Class_Type = rttr::detail::invalid_type; A = int; acc_level = rttr::detail::public_access; Visitor_List = rttr::type_list<>; rttr::string_view = rttr::basic_string_view]': D:/mingw64/x86_64-w64-mingw32/include/rttr/detail/registration/bind_impl.h:596:49: required from 'rttr::registration::bind<rttr::detail::prop_readonly, Class_Type, A, acc_level, Visitor_List>::~bind() [with Class_Type = rttr::detail::invalid_type; A = int; acc_level = rttr::detail::public_access; Visitor_List = rttr::type_list<>]' error: no type named 'type' in 'struct rttr::detail::property_type' 548 | using acc_type = typename property_type::type; | ^~~~ error: no type named 'type' in 'struct rttr::detail::property_type' 549 | return detail::make_unique<property_wrapper<acc_type, Class_Type, A, void,
| ~~^~~~~~~~~~~~~
550 | detail::map_access_level_to_enum::value, | ~~~~~~~~~~~ 551 | default_getter_policy, default_setter_policy, 0, Visitor_List | ~~~~~~~~~~~~~ 552 | > | ~ 553 | >(name, acc, std::array<detail::metadata, 0>());
| ~

include<rttr/registration>

include<rttr/registration_friend>

include

using namespace rttr; using namespace std; struct A { A(){}; void func(double){} int data; RTTR_ENABLE() RTTR_REGISTRATION_FRIEND }; void func(double){} int aaa;

RTTR_REGISTRATION { registration::method("func",func); registration::propertyreadonly("aaa",aaa); registration::class("A") .method("func",&A::func); } int main(int argc, char const *argv[]) { // string s; // cin>>s; rttr::type::get_by_name("A"); return 0; }

What should I do?