From ab7d22bc3f6b4950b758a2f646949db6e8d04e7b Mon Sep 17 00:00:00 2001 From: Dup4 Date: Wed, 29 Jun 2022 18:52:42 +0800 Subject: [PATCH] feat: add throw error when class has no target function --- include/autowired/autowired.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/autowired/autowired.h b/include/autowired/autowired.h index 9bb741d..497489d 100644 --- a/include/autowired/autowired.h +++ b/include/autowired/autowired.h @@ -210,18 +210,24 @@ class AutoWired { node.func_Init = [t_ptr] { t_ptr->Init(); }; + } else if (node.options.need_init) { + throw std::runtime_error("Class has no Init() function"); } if constexpr (internal::has_de_init_v) { node.func_DeInit = [t_ptr] { t_ptr->DeInit(); }; + } else if (node.options.need_de_init) { + throw std::runtime_error("Class has no DeInit() function"); } if constexpr (internal::has_auto_wired_v) { node.func_AutoWired = [t_ptr] { t_ptr->AutoWired(); }; + } else if (node.options.need_auto_wired) { + throw std::runtime_error("Class has no AutoWired() function"); } class_.emplace(name, std::move(node));