StudyLover
  • Home
  • Study Zone
  • Profiles
  • Contact us
  • Sign in
StudyLover 27. Program to use pointers for both base and derived classes and call the member functions using the `virtual` keyword.
Download
  1. C++ Programs list
26. Program to implement exception handling with & without the functionality of testing throw restrictions. : 28. Program to illustrate the concepts of console I/O operations.
C++ Programs list

1.      Program to use pointers for both base and derived classes and call the member functions using the `virtual` keyword.

  1. #include <iostream.h>

  2. #include<conio.h>

  3. class Base {

  4. public:

  5.     virtual void show() {

  6.                 cout << "Base class" << endl;

  7.     }

  8. };

  9. class Derived : public Base {

  10. public:

  11.     void show() {

  12.                 cout << "Derived class" << endl;

  13.     }

  14. };

  15. int main() {

  16.     Base *ptr;

  17.     Derived obj;

  18.     ptr = &obj; // Pointer to base class pointing to derived class object

  19.     ptr->show(); // Calls the derived class's show() function due to virtual keyword

  20.     getch();

  21.     return 0;

  22. }

26. Program to implement exception handling with & without the functionality of testing throw restrictions. 28. Program to illustrate the concepts of console I/O operations.
Our Products & Services
  • Home
Connect with us
  • Contact us
  • +91 82955 87844
  • Rk6yadav@gmail.com

StudyLover - About us

The Best knowledge for Best people.

Copyright © StudyLover
Powered by Odoo - Create a free website