From c19c034b31fd4271f0d73800b460db8553de9971 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Thu, 9 Jan 2025 00:43:37 +0800 Subject: [PATCH] Added InheritTest.cpp --- CMakeLists.txt | 1 + datatype/typeinfo/InheritTest.cpp | 70 +++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 datatype/typeinfo/InheritTest.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index a1ed93e..41e21a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,6 +39,7 @@ cm_example_project("DataType/TypeInfo" TypeSizeof datatype/TypeInfo/Ty cm_example_project("DataType/TypeInfo" TypeCastTest datatype/TypeInfo/TypeCastTest.cpp) cm_example_project("DataType/TypeInfo" TypeCheck datatype/TypeInfo/TypeCheck.cpp) cm_example_project("DataType/TypeInfo" ObjectRelationTest datatype/TypeInfo/ObjectRelationTest.cpp) +cm_example_project("DataType/TypeInfo" InheritTest datatype/TypeInfo/InheritTest.cpp) #################################################################################################### cm_example_project("DataType" HalfFloatTest datatype/HalfFloatTest.cpp) diff --git a/datatype/typeinfo/InheritTest.cpp b/datatype/typeinfo/InheritTest.cpp new file mode 100644 index 0000000..7c8a3bb --- /dev/null +++ b/datatype/typeinfo/InheritTest.cpp @@ -0,0 +1,70 @@ +#include +#include + +class Object +{ +public: + + virtual size_t GetTypeHash()const noexcept=0; + virtual const char *GetTypeName()const noexcept=0; +}; + +template class Inherit:public BASE +{ +public: + + static const size_t StaticHash()noexcept + { + return typeid(T).hash_code(); + } + + virtual size_t GetTypeHash()const noexcept override + { + return T::StaticHash(); + } + + static const char *StaticName()noexcept + { + return typeid(T).name(); + } + + virtual const char *GetTypeName()const noexcept override + { + return T::StaticName(); + } +};//template class Inherit:public T + +class TestClass:public Inherit +{ +}; + +class TestClassA:public Inherit +{ +}; + +class TestClassB:public Inherit +{ +}; + +template void out(const char *name,T *obj) +{ + std::cout<GetTypeName()<<": "<GetTypeHash()<("ta",&ta); + out("tb",&tb); + + return 0; +}