pure virtual

pure virtual - cout<< "Enter 1 for A or...

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

View Full Document Right Arrow Icon
class A{ public: static int x; blahblahblah code here #include "A.h" int A::x=9; static member declared outside of any function must initialize static data members because they exist as soon as its compiled, not when their objects are instantiated class A{ private: int x; public: A(int val): x(val){} virtual void print(){ cout << "A::X = " << x<< endl; }; class B: public A{ private: int y; public: B(int val1, int val2): A(val1), y(val2){}
Background image of page 1

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

View Full DocumentRight Arrow Icon
virtual void print(){ cout<< "B::y = " << y << endl; } }; int choice; A* ptrs[10]; for(int i = 0; i < 10; i ++){
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: cout<< "Enter 1 for A or "<< "2 for B: " ; cin << choice; if(choice==1){ { ptrs[i] = new A(i); } else{ ptrs[i] = new B(i, i*i); } for(int i = 0; i < 10; i++) ptrs[i] -> print(); } pure virtual function-does not have implementation if a class inherits from another class with a pure virtual function, then it must provide an implementation or the method is still pure virtual in the derived class a class with a pure virtual method is called an abstract class...
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

pure virtual - cout<< "Enter 1 for A or...

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