overriding functions polymorph

overriding functions polymorph - public: virtual void...

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

View Full Document Right Arrow Icon
Overriding funtions provide a new implementation of a base class function in a derived class class super{ public: void print(){ cout<< "hello" << endl; } } class sub: public super{ public: void foo(){ cout<< "foo" << endl; } } main(){ sub b; b.foo(); b.print(); super * sPtr = &b; sPtr-> print(); } Polymorphism- dynamic binding class shape{ public: virtual void draw(){ } }; class circle: public shape{
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: public: virtual void draw(){ cout&lt;&lt; &quot;Imacircle&quot; &lt;&lt; endl; } }; class triangle: public shape{ public: virtual void draw(){ cout&lt;&lt; &quot;triangle&quot; &lt;&lt; endl; } }; int main(){ shape * s; int p; cout&lt;&lt; &quot;enter 1 for circle or 2 for other&quot; &lt;&lt; endl; cin&gt;&gt;p; if(p==1){ s= new circle(); } else{ s = new triangle(); } s-&gt;print(); }...
View Full Document

This note was uploaded on 11/11/2009 for the course CSE 2341-H taught by Professor Markfontenot during the Spring '09 term at SMU.

Page1 / 2

overriding functions polymorph - public: virtual void...

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