Program to illustrate Inline Constructor


#include <iostream.h>
#include <string.h>
#include<conio.h>
class sample
{
    char itemname[20];
    int cost;
    public :
    sample(char* s, int c)    // Inline Constructor
    {
        strcpy(itemname,s);
        cost = c;
    }
    void print_data();
};
void sample::print_data()
{
    cout << "Item : " << itemname << "\n";
    cout << "Cost : " << cost << "\n";
}
void main(void)
{
    clrscr();
    sample A("MyItem", 100);
    A.print_data();
    getch();
}

0 comments:

Post a Comment

 
 
 
 


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