#include<iostream.h>
#include<conio.h>
class add
{
private:
int a,b;
public:
void getdata(int a,int b)
{
this->a=a;
this->b=b;
}
void display()
{
int c;
c=a+b;
cout<<"\n NAswer="<<c;
cout<<"\n this=="<<this;
}
}
main()
{
clrscr();
int a,b;
add a1,a2;
cout<<"enter first no.";
cin>>a;
cout<<"enter second no.";
cin>>b;
a1.getdata(a,b);
a1.display();
a2.getdata(6,3);
a2.display();
getch();
}
------------------------------------------------------------------------------------------------------------------------------------------------------------
It is a misbelief that the 'this' pointer is a hidden member of a class or struct. It is a hidden parameter of non-static member functions. When you declare a function the compiler adds an extra parameter to function's prototype. The type of the parameter depends on how the function is declared.
No comments:
Post a Comment