/*
How to differentiate our data member and local variable using this pointer
*/
#include<iostream>
using namespace std;
class Test
{
int a,b;
public:
void accept(int a,int b)
{
this->a=a; //Pointer to member access operator
(*this).b=b;
}
void display()
{
cout<<"\n\n A: "<<a;
cout<<"\n\n B: "<<b;
}
};
int main()
{
Test t;
t.accept(10,20);
t.display();
return 0;
}
How to differentiate our data member and local variable using this pointer
*/
#include<iostream>
using namespace std;
class Test
{
int a,b;
public:
void accept(int a,int b)
{
this->a=a; //Pointer to member access operator
(*this).b=b;
}
void display()
{
cout<<"\n\n A: "<<a;
cout<<"\n\n B: "<<b;
}
};
int main()
{
Test t;
t.accept(10,20);
t.display();
return 0;
}