Sunday, February 25, 2018

C ++ program : Type Casting example

#include <iostream>
using namespace std;
class A {
protected:
    int i;
public:
    A(int a = 0) : i(a) {}
void fun() { cout << i; }
};
class B :public A{
public:
    B(int a = 0) : A(a) {}
 virtual void fun() { cout << i*10; }
};
class C :public B{
public:
    C(int a = 0) : B(a) {}
 virtual void fun() { cout << i*15; }
};
int main(){
    int num;
    cin >> num;
    B *bp = new C(num);
    bp->fun();
    return 0;
}

Thanks
Happy Programming !

1 comment:


  1. You can certainly see your expertise within the article you write. The arena hopes for even more passionate writers like you who aren’t afraid to mention how they believe. All the time go after your heart.

    IGNOU Courses
    IGNOU Study Material
    IGNOU Syllabus
    IGNOU Assignments
     IGNOU Study Center
    IGNOU MBA Study Material

    ReplyDelete

How can I run a C++ program directly from Windows?

How-can-I-run-a-C-program-directly-from-Windows