c++ - get derived classes access the member data and functions of each other -


Using member data and work of each other to create derivative orbits, both sections should be treated as a pure summary Inherited from the base class.

Here my scenario

  class base {public: virtual zero do_something () = 0; }; Class Derive1: Public Base {Public: Virtual Zero do_something () {// need to use a2 / need to use Func} Personal: int a1; }; Category Derived2: Public base {Public: Virtual Zero do_something () {// 1}} need to use zero func () Private: int a2; };  

Maybe you need to think about your design again There will be no allocated memory and likewise what you are asking for A2 and Derivative 1 is equal to saying, both cat and dog are animals, I want to use cat :: fork in the dog. You probably need it:

  class base {public: virtual zero do_something () = 0; }; Class derivatives: Public base {public: int a1; Int A2; Zero func () {}}; Class Derive1: Public Derivatives {Public: Virtual Void do_something () {// can use A2 and func}}}; Class derivative 2: public derivative {public: virtual zero do_something () {// need to use a1} zero func () override {}};  

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%? -