Virtual Functions with Inline Code Substitution Assignment Help

Assignment Help: >> Polymorphism - Virtual Functions with Inline Code Substitution

Virtual functions with inline code substitution

Virtual functions could be declared as an inline code, being the run time binding of the computer. An inline code does not affect much of the programming effectiveness.  A compiler must get information about the functions, such as from where they have to be invoked.

The common form is:

Class base

{

private:

//data;

public:

};

// syntax :virtual inline return_type function_name(argruments);

             virtual inline return_type function_name(argruments);

// description of inline code along with virtual function

# include<iostream.h>

class base

{

private:

int x;

float y;

public:

virtual inline void getdata( );

virtual inline void display( );

};

class derivedB : public base

{

private:

int rollno;

char name[20];

public:

};

void getdata ( );

void display ( );

void base :: getdata ( )

{

cout <<"enter an integer \n";

cin>> x;

cout<<"enter a real number \n";

cin<< y;

}

void base :: display( )

{

cout<<" numbers x = "<< x

cout<< "and y = " << y;

cout<< endl;

}

void derivedB :: getdata ( )

{

cout <<"enter roll number \n";

cin >> rollno;

cout<< "enter name of a student \n";

cin>> name;

}

void derivedB :: display ( )

{

cout << "roll number  student's name \n";

cout << roll no << '\t' << name << endl;

}

void main ( )

{

base *ptr;

derivedB obj;

ptr = &obj;

ptr-> getdata ( );

ptr -> display ( );

}

Output of the above program is:

Enter roll number

89001

enter name of a student ganapathy

rollnumber   student's name

89001              ganapathy

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd