c++ - Policy based design - policy implementation has to access members of the host class -


I think the best way to explain my question is with one part of the code:

< Pre> class IncreasingMultiplier {protected: IncreasingMultiplier (integer initialMultiplier = 0, integer incrementation = 1) int getMultiplier () {mCurrentMultiplier + = mIncrementation; Return mCurrentMultiplier - mIncrementation; } Zero set multiplier (mtm); {mCurrentMultiplier = multiplier; } Zero set incrementation (mincreation = induction; } Private: int mCurrentMultiplier; Int mIncrementation; `} Category ConstMultiplier {protected: int getMultiplier () const {return 10; }} Class number logger {public: zero log () {int currentNumber = getNumber (); // How can I call this method? Std :: cout & lt; & Lt; "Current number is" & lt; & Lt; Current number & lt; & Lt; Std :: endl; }} Template & lt; Class multiplier policy, class logging policy & gt; Class Host: Public Multiplier Policy, Public Logging Policy {Public: int getNumber () const {return mNumber * getMultiplier (); } Private: int mNumber; }

In fact, a policy may need access to defined members in the host category, which is dependent on other policies provided for the host class.

Thank you!

"post-text" itemprop = "text">

The following codes are compiled with VS2013 (not tried with GCC):

  # Include & lt; Iostream & gt; Class IncreasingMultiplier {Protected: IncreasingMultiplier (integer initialMultiplier = 0, integer incrementation = 1): mCurrentMultiplier (initialMultiplier), mIncrementation (incrementation) {} integer getMultiplier () {mCurrentMultiplier + = mIncrementation; Return mCurrentMultiplier - mIncrementation; } Zero set multiplier (mtm); {mCurrentMultiplier = multiplier; } Zero set incrementation (amincretion = increase; } Private: int mCurrentMultiplier; Int amincreation; }; Class ConstMultiplier {secure: int getMultiplier () const {return 10; }}; // Template Logger Policy // Unfortunately - No Visual Studio 2013 :( // https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern Template can get // host legacy CRTP pattern; typename t_Host & gt; ; Category: NumberLogger / *: public t_Host * / {public: zero log ()} // This part of CRTP pattern does work in Visual Studio 2013 Integer currentNumber = static_cast & lt; t_Host *> (this) -> gt; ; GetNumber (); // How can I call this method std :: The court & lt;? & Lt;  

The resulting output is:

  const policy: current number is 10 current number 10 is current number 10 increasing policy current number 0 current number is 1 Current number is 2  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -