c++ - Callbacks from private CRTP bases -


The following code does not work, because you can not do static_cast from the private base class.

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?

  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; }   

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.

  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

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -