inheritance instantiation

inheritance instantiation - Can say: C*ptr = new C; delete...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
class employee{ public: virtual double pay() = 0; }; class manager: public employee{ public: virtual double pay(){ cout<< "Manager Pay" << endl; } }; NOTE: Can not say: employee e; // cannot instantiate an abstract class with a pure virtual method Can say: employee * ptr = new manager; class A{ } class B: public A{ private: int*p; }; class C: public A{ private: char* c; }; NOTE: Cannot say: A* ptr = new C; delete ptr; // because it does not know what kind of destructor to call
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Can say: C*ptr = new C; delete ptr; // because it knows to delete the kind in C Can also change class A,B,C to contain: public: virtual ~A/B/C{. ......... }; Why do you want a virtual destructor in a cpp class? So that the derived class destructor is called instead of a base class destructor, this way if you declare a a sub class object with a base class ptr you can still delete the object....
View Full Document

Page1 / 2

inheritance instantiation - Can say: C*ptr = new C; delete...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online