Sunday, February 25, 2018

C++ program : Polymorphism and Virtual Functions

#include <iostream>
using namespace std;
class Base {
public:
    virtual void show() = 0;
};
class Derived : public Base {
    int i;
public:
    Derived(int num) : i(num) { i = i * 2; }
void show(){cout<<i;}




};
int main() {
    int n;
    cin >> n;
    Derived d(n);
    Base &b = d;
    b.show();
    return 0;
}

Thanks
Happy Computing !

No comments:

Post a Comment

Sacred Thought

5 May 2024 Hari Om Verse 50-51, chapter two:  In this chapter two Shree krishna explains a simple way of living. Free from desires and void ...