Memeber function declare outside the class declarartion
Member function declared inside a class are called inline function.It is not always good to make the member function inline.If class has so many numbers of member function and their methods areso long,in this case we have to face a problem i.e how many member functions are present in the class.So in this situation we have to declare all the member function outside the class declaration.To declare a member function outside the class declaration 1st we have to place the function prototype within the class.Then we have to declare the member function outside the class declaration with the following syntax.
Syntax:
returntype classname ::member functionname(){
--------
--------
}
//This program illustrate member function declare outside the class declartion.
#include>iostream.h>
#include<conio.h>
class employee
{
private:
int eno;
char ename[15
float sal;
public:
void getdata();//function prototype
void putdata()
};
void employee::getdata(0
{
cout<<"Enter employee number-:";
cin>>eno;
cout<<"Enter employee name-:";
cin>>ename;
cout<<"Enter salary ampount-:";
cin<<sal;
}
void employee ::putda()
{
cout<,"Employee number-"<<eno<<endl;
cout<<"Employee name-"<<ename<<endl;
cout<<"Salary amount<<sal<,endl;
}
viod main()
{
clrscr()
employee e1;
e1.employee();
e1.putdata();
getch(0;
}
To read more clcik the link Click here
Email:akashkumarswain14@gmail.com
No comments:
Post a Comment
Thanks for join with us.