quote:Original post by Anonymous Poster
I don''t think anybody explained this:
Explained what?
quote:
that will put "SNORE" onto the screen.
It shouldn''t even compile. What are you trying to demonstrate?
quote:Original post by Anonymous Poster
I don''t think anybody explained this:
quote:
that will put "SNORE" onto the screen.
//somewhere abovevector<Shape *> shapesList;//somewhere in the middle//Circle and Square are derived from ShapeshapesList.push_back(new Circle());spahesList.push_back(new Square());//later on during cleanupfor (int i = 0; i < shapesList.size(); ++i) delete shapesList[ i ];
quote:Original post by Whoknewb
Maybe I''m thick header but I''m not exactly getting this.
quote:
what? I''ve heard that you should always make constructors/destructors virtual if you plan on ever deriving a class from it.
quote:
What is the point of making a constructor/destructor virtual if you''re going to use the base and derived class''s destructors and not inherit the base''s destructor?
quote:
Also, why do you do CBase *pDerived = new CDerived; ?
quote:
As the AP pointed out you can just do
CDerived *pDerived = new CDerived;
class CBase{public: CBase(); ~CBase(); vector& GetA(void) const { return A; } void AddtoA(const double val) { A.push_back(val); }private: vector<double> A;};class CDerived : public CBase{public: CDerived(); ~CDerived();};CBase *pDerived1 = new CDerived;CBase *pDerived2 = new CDerived;pDerived1->AddtoA(3.0);pDerived2->AddtoA(4.0);
quote:
quote:
--------------------------------------------------------------------------------
Original post by Whoknewb
When you publicly inherit from a base class, do you inherit it''s private variable members?
--------------------------------------------------------------------------------
Yes. You inherit everything. Only, you can''t access the private members because they''re private to the base class. So, they are there, but you can''t get at ''em.
quote:
--------------------------------------------------------------------------------
Also if you do inherit the member variables does each instance of the derived class get it''s own copy or by modifying the derived class''s inherited members not only modify itself, but also the base class and any other class that inherits those members?
--------------------------------------------------------------------------------
Look at it this way. The entire base class becomes a part of the derived class. The derived *is a* base class plus some. So, no, the derived class doesn''t create a new copy of the members.
quote:Original post by Whoknewb
You say that each derived class gets its own copy of the members, when SabreMan says "the derived class doesn''t create a new copy of the members."