Polymorphism-Virtual Fun
Polymorphism-Virtual Fun
Polymorphism-Virtual Fun
Pointers to Objects
• Object pointers are useful in creating objects at run time.
• We can also use an object pointer to access the public members of an
object.
• Consider following example
class item
{
int code;
float price;
public:
void getdata(int a, float b)
{
code =a;
price=b; }
void show(void)
{
cout<<“Code= “<<code<<endl;
cout<<“Price= “<<price<<endl; } };
Pointers to Objects
• item x;
item *ptr = &x // Pointer ptr is initialized with the address of
x
NOTE :
NOTE :