c++ - Callbacks from private CRTP bases -
The following code does not work, because you can not do Changing cast with C-style artists (although I basically thought it would apply undefined behavior, apparently it does not seem), rather it's ugly because it gives you the power of Constant- Allows bypassing checking, etc. There will be another way for CRTPs to be a friend, but they will expose all the derived personal members. Is there another way to write it without using the C-style and without making CRPPs a Friend? I think the best solution is to avoid personal heritage and instead The option to hide data is to choose between Marking protected member function will prevent access to everywhere except derived sections. Instead another bonus public succession is used. static_cast from the private base class.
template & lt; Typename T & gt; Struct CRTPBase {Zero Counts () {T * Derived = Fixed_ of & lt; T * & gt; (this); derived-> PublicMethod (); }}; Structured Derivatives: Private CRTPBase & lt; Derived & gt; {Void callParent () {this- & gt; Callbase (); } Zero public method () {}}; Int main () {Derived D; D.callParent (); Return 0; }
template & lt; Typename T & gt; Square CRTPBase {Protected: Zero CallBase () {T * Derived = Fixed_Cast & lt; T * & gt; (this); Derived-> publicMethod (); }}; Structured Derivatives: Public CRTPBase & lt; Derived & gt; {Void callParent () {this- & gt; Callbase (); } Zero public method () {}}; Int main () {Derived D; D.callParent (); D.callBase () // & lt; - Invalid return 0; }
Comments
Post a Comment