I want to use the Peimple idiom from heritage.
The base is the public class and its implementation class:
class A {Public: A () {PAMML = New AIMPL;}; Void foo () {pAImpl- & gt; Foo ();}; Private: AIMPL * PAMML; }; Class AIMPL {public: zero foo ()} {/ * doing something *}; };
And I want to be able to create derivative public classes with my implementation class:
class B: Public A {public: zero times () {PAImpl- & gt; times ();}; // can not do! Pampal A is private}; Class BImpl: Public AIMPL {Public: zero times ()) / / do something else; };
But I can not use the pAimpl in B because it's A's private.
So I look at some ways to solve it:
- Create BImpl * pBImpl member in B> B, and in A with additional A constructor, A (AIMPL *) Pass it.
- Change PAIMPL (or add gate function) to protect, and use it to b.
- B should not be obtained from B Make BImpl * pBImpl members in B, and create foo () and bar (in B), which will use pBImpl.
- Anyone on the other side?
What should I choose?
class A {public: a (boolean doyew = true) {if (duew) PAIML = New AIMPL; }; Void foo () {pAImpl- & gt; Foo ();}; Protected: Zero SetpAImpl (AIMPL * PIMPL) {pAImpl = pImpl;}; Private: AIMPL * PAMML; }; Class AIMPL {public: zero foo ()} {/ * doing something *}; }; Class B: Public A {Public: B (): A (wrong) {pBImpl = new BImpl; SetpAImpl (pBImpl); }; Zero times () {pBImpl-> times ();}; Private: BImpl * pBImpl; }; Class BImpl: Public AIMPL {Public: zero times ()) / / do something else; };
Comments
Post a Comment