database - Unique base class instance -


I am developing a C + + DLL which contains three sections: base class base , Derived1 and Derived2 category. Scenario:

  class base {// ctor, dtor, members and methods here} class Derived1: public base {// ctor, dtor, members and methods here} class Derived2: public base {/ / Ctor, dtor, members and methods here}  

I am making with MS VC ++ 2008 Express, I use under Turbock ++ (Borland: Very Good ID / Red) Want to .

I export Facotry method through Derive1 , and through the client code, Derived1 creates Derived2 . Share both Derived1 and Derived2 , both of the Pointer functions contained in another DLL, so I put that pointer function under the base class.

There is a problem here once I make an example (via the factory) of Derived1 and it can make many examples of Derived2 , Then the constructor of the class base is called more often (many times for Derived1 and Derived2 )

How can I stop many of the base efforts?

Another question:

In the scenario I have previously described, Derived1 call code> Derived2 Of multiple verbs and both the Derived1 and Derived2 unique general base class. I ask: Is this a bad design? Is there another design of the classes and their heritage hierarchy better than what I have used?

Many instances of the base you can prevent many instances of the pointer - make it static: < / P>

  class base {public: // save first pointer passed to me (sometype * p) {if (myptr == 0} {Myptr = p; }} Personal: static sometype * myptr; };  

In a C ++ source file, you will need to define myptr:

  sometype * base :: myptr = 0;  

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