Passing Reference To Object In C++
Here
object generated one copy and also normal variable can call fast so that kind
is used through function to call we have to use dot. Operator or arrow operator
in passing reference to object.
Fig: Passing Reference To Object In C++
Fig: Passing Reference To Object In C++
Synatx:
return
type fuctionname(classname &objectname)
{
function
of body;
}
Program:
#include<iostream.h>
#include<conio.h>
class
MCA
{
int
a;
public:
void
input();
void
output(MCA &b1)
{
cout<<b1.a;
}
};
void
MCA::input()
{
cout<<”input
one value”;
cin>>a;
}
void
main()
{
MCA
a1,b2;
a1.input();
b2.output(a1);
getch();
}
Output:
Input
one number 4
4
#include<iostream.h>
#include<conio.h>
class
MCA
{
int
a;
public:
void
input();
void
output(MCA &b1)
{
cout<<b1.a;
}
};
void
MCA::input()
{
cout<<”input
one value”;
cin>>a;
}
void
main()
{
MCA
a1,b2;
a1.input();
b2.output(a1);
getch();
}
Output:
Input
one number 4
4
No comments:
Post a Comment