diff --git a/ZCppMain/ZMainHead.H b/ZCppMain/ZMainHead.H index bdb787d..5ce64da 100644 --- a/ZCppMain/ZMainHead.H +++ b/ZCppMain/ZMainHead.H @@ -1243,7 +1243,7 @@ namespace ZNsMain //////////////////////////////////////////////////////////////////////////////////////////*/ - /*///////////////////////////////////////////////////////////////////////////////////////////////////////////// + /*######################################################################################### ■ class ZtCTypeCRTP<> 의 단점은 상속하지 않은 class 형은 알 수 없는데, 이것을 알아내기 위해 @@ -1275,30 +1275,65 @@ namespace ZNsMain 정말 멋진 기교가 아닌가. C++ 의 향기에 잠시 취해 보자. -- 2013-06-10 00:33:00 - /////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ + ■ ZtCTypeNowCRTP 의 template parameter 에 bool TTypebUseCRTP 추가. -- 2025-09-28 15:55 - template - class ZtCTypeNowCRTP - { - public: enum{ZEUseCRTP=1}; - public: typedef TTypeChild TypeData; - public: typedef TTypeNow TypeBase; - }; - template - class ZtCTypeNowCRTP - { - public: enum{ZEUseCRTP=0}; - public: typedef TTypeNow TypeData; - public: typedef TTypeNow TypeBase; - }; - template - class ZtCTypeNowCRTP - { - public: enum{ZEUseCRTP=0}; - public: typedef TTypeNow TypeData; - public: typedef TTypeNow TypeBase; - }; - //////////////////////////////////////////////// + TTypeChild 가 ZCEmpty 이거나 TTypebUseCRTP 이 false 이면, 아래가 된다. + + public: enum{ZEUseCRTP=0}; + public: typedef TTypeNow TypeData; + public: typedef TTypeNow TypeBase; + + ■ 3번 template parameter 가 bool TTypebUseCRTP 인데, 만약 TTypeChild 가 유효한 자료형이라 + 면, TTypebUseCRTP 이 true 인 것이 맞겠으나, DEBUG 등의 특수한 용도로 TTypebUseCRTP 을 + false 로 설정할 수 있게 한 것이다. + + 주로 ZtCTypeCRTP 와 같이 사용해, 가상 함수를 사용하지 않고도 상속을 통해 다형성을 구현하 + 거나 기능 확장을 하고 싶을 때 사용한다. 보통 CRTP 는 상속을 전제로 하는 상황에서 주로 쓰 + 이지만, ZtCTypeNowCRTP 는 꼭 상속하지 않아도 된다. + + 사용예는 ZtCBaseList 에 있다. + + -- 2025-09-28 16:13 + + #########################################################################################*/ + + template + + class ZtCTypeNowCRTP + { + public: enum{ZEUseCRTP=(ZTypIntE)TTypebUseCRTP}; + /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ + public: typedef TTypeChild TypeData; + public: typedef TTypeNow TypeBase; + }; + + template + + class ZtCTypeNowCRTP + { + public: enum{ZEUseCRTP=0}; + public: typedef TTypeNow TypeData; + public: typedef TTypeNow TypeBase; + }; + + template + + class ZtCTypeNowCRTP + { + public: enum{ZEUseCRTP=0}; + public: typedef TTypeNow TypeData; + public: typedef TTypeNow TypeBase; + }; + + template + + class ZtCTypeNowCRTP + { + public: enum{ZEUseCRTP=0}; + public: typedef TTypeNow TypeData; + public: typedef TTypeNow TypeBase; + }; + ///////////////////////////////////////////////////////// @@ -5239,11 +5274,11 @@ namespace ZNsMain typedef ZCLink* iterator ; public: - typedef ZNsType::ZtCTypeNowCRTP /////////////////// + typedef ZNsType::ZtCTypeNowCRTP /////////////////////////////////////// < - ZtCBaseList, typename TTypeCRTP::TypeData + ZtCBaseList, typename TTypeCRTP::TypeData, TTypeCRTP::ZEUseCRTP > - ZCTypeNowCRTP ; /////////////////////////////////// + ZCTypeNowCRTP ; /////////////////////////////////////////////////////// typedef typename ZCTypeNowCRTP::TypeData TypeChild; @@ -5355,11 +5390,19 @@ namespace ZNsMain TypeSize ml_LinkCnt ; private : + TypeChild& GetChildObj() + { + return *static_cast(this); + }/* + TypeChild& GetChildObj()*/ + + private : + _VT_ ZCLink* NewLink() { if(TTypeCRTP::ZEUseCRTP<1) return new ZCLink; - return (*static_cast(this)).NewLink(); + return GetChildObj().NewLink(); }/* _VT_ ZCLink* NewLink()*/ @@ -5368,7 +5411,7 @@ namespace ZNsMain if(TTypeCRTP::ZEUseCRTP<1) { return new ZCLink(AO_ArgData); } - return (*static_cast(this)).NewLink(AO_ArgData); + return GetChildObj().NewLink(AO_ArgData); }/* _VT_ ZCLink* NewLink(TypeArg AO_ArgData)*/ @@ -5377,7 +5420,7 @@ namespace ZNsMain if(TTypeCRTP::ZEUseCRTP<1) { delete AP_DelLink; return; } - return (*static_cast(this)).DelLink(AP_DelLink); + GetChildObj().DelLink(AP_DelLink); }/* _VT_ void DelLink(ZCLink* AP_DelLink)*/ diff --git a/ZCppMainTest/ZtCBaseList_000.cpp b/ZCppMainTest/ZtCBaseList_000.cpp index d62e466..37d8f9a 100644 --- a/ZCppMainTest/ZtCBaseList_000.cpp +++ b/ZCppMainTest/ZtCBaseList_000.cpp @@ -67,7 +67,6 @@ namespace ZNsMain {cout<<"#6 Value="< CStringBase ; @@ -84,6 +83,159 @@ namespace ZNsMain typedef ZtCBaseList CStringList2 ; + public: + + + class ZCBaseListEx10 : public ZtCBaseList + < + CStringBase + , CStringBase& + , ZCAllocator + , ZTypLong + , ZNsMain::ZtCMoveObj + , ZNsType::ZtCTypeCRTP + > + { + public : + + template ////////////////////////////////////////////////////////////////// + < + typename TType , typename TTypArgu , + typename TTypeAlloc , typename TTypSize , + typename TMoveObj , typename TTypeCRTP + > + friend class ZtCBaseList; /*#############################################*/ + + typedef ZtCBaseList /////////////////////////////////////////////////////// + < + CStringBase + , CStringBase& + , ZCAllocator + , ZTypLong + , ZNsMain::ZtCMoveObj + , ZNsType::ZtCTypeCRTP + > + ZCBaseList; /////////////////////////////////////////////////////////////// + + friend class ZtCBaseList ////////////////////////////////////////////////// + < + CStringBase + , CStringBase& + , ZCAllocator + , ZTypLong + , ZNsMain::ZtCMoveObj + , ZNsType::ZtCTypeCRTP + >; + /////////////////////////////////////////////////////////////////////////// + + typedef typename ZCBaseList::ZCLink ZCLink; + + private: + + _VT_ ZCLink* NewLink() + { + cout<<"** ZCBaseListEx10 : NewLink()"< + , ZNsType::ZtCTypeCRTP + > + { + public : + + template ////////////////////////////////////////////////////////////////// + < + typename TType , typename TTypArgu , + typename TTypeAlloc , typename TTypSize , + typename TMoveObj , typename TTypeCRTP + > + friend class ZtCBaseList; /*#############################################*/ + + typedef ZtCBaseList /////////////////////////////////////////////////////// + < + CStringBase + , CStringBase& + , ZCAllocator + , ZTypLong + , ZNsMain::ZtCMoveObj + , ZNsType::ZtCTypeCRTP + > + ZCBaseList; /////////////////////////////////////////////////////////////// + + friend class ZtCBaseList ////////////////////////////////////////////////// + < + CStringBase + , CStringBase& + , ZCAllocator + , ZTypLong + , ZNsMain::ZtCMoveObj + , ZNsType::ZtCTypeCRTP + >; + /////////////////////////////////////////////////////////////////////////// + + typedef typename ZCBaseList::ZCLink ZCLink; + + private: + + _VT_ ZCLink* NewLink() + { + cout<<"** ZCBaseListEx11 : NewLink()"<