Program to illustrate Inline Member Functions


#include <iostream.h>
#include<conio.h>
/*----------------------Class definition-------------------------*/
class sample
{
        int a;
    public :

        // inline member functions
    void setdata(int x)
    {
       a = x;
    }
        void print_square() {cout << "sqr(a) = " << a*a << "\n";}
        void print_cube();
};
// inline member function
inline void sample::print_cube()
{
    cout << "cube(a) = " << a*a*a << "\n";
}
/*----------------------Definition ends here---------------------*/
void main(void)
{
    clrscr();
    sample num;

    num.setdata(10);
    num.print_square();
    num.print_cube();
    getch();
}

0 comments:

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|