this keyword in cpp

Solutions on MaxInterview for this keyword in cpp by the best coders in the world

showing results for - "this keyword in cpp"
Benjamin
28 Aug 2020
1#include <iostream>
2class Entity
3{
4public:
5	int x, y;
6	Entity(int x, int y)
7	{
8		Entity*const e = this;// is a ptr to the the new instance of class 
9		//inside non const method this == Entity*const
10		//e->x = 5;
11		//e->y =6;
12		this->x = x;
13		this->y = x;
14	}
15	int GetX()const
16	{
17		const Entity* e = this;//inside const function this is = const Entity*
18	}
19};
20
21int main()
22
23{
24	Entity e1(1,2);
25}
Eric
18 Oct 2017
1 this is a keyword that refers to the current instance of the class. 
2 There can be 3 main usage of this keyword in C++. It can be used to 
3 pass current object as a parameter to another method. 
4 It can be used to refer current class instance variable.
5   
6#include <iostream>
7using namespace std;
8class Demo {
9private:
10  int num;
11  char ch;
12public:
13  void setMyValues(int num, char ch){
14    this->num =num;
15    this->ch=ch;
16  }
17  void displayMyValues(){
18    cout<<num<<endl;
19    cout<<ch;
20  }
21};
22int main(){
23  Demo obj;
24  obj.setMyValues(100, 'A');
25  obj.displayMyValues();
26  return 0;
27}
28
29Output:- 
30  	100
31	A
queries leading to this page
c 2b 2b when to use this pointerthis 3e cpprole of this pointerhow to use this keyword in c 2b 2btwo situvation using this pointerthis variable in c 2b 2bthis pointer is present inew pointer and this pointerusing this in c 2b 2bthis pointer in c 2b 2b example programthis c 2bthis keyword c 2b 2bgeek for geeks this keyword cppthis in c 2b 2b classc 2b 3d this keywordthis pointerthis pointer gfgprint member function c 2b 2b to print which object has invoked it using this pointer in cppc 2b 2b this in cppthis in c 2b 2bwhat does this do in c 2b 2bthis in class c 2b 2bthis keyword in c 2b 2bthis is c 2b 2bwhat is 22this 22 in c 2b 2bhow to use this keyword c 2b 2bthis pointer represents the current class data memberslet keyword in c 2b 2bthis keyword cppthis in c 2bwhy to use this keyword in c 2b 2bthis function c 2b 2bdis pointer in c 2b 2busing this statement in c 2b 2bhow to acess this pointerthis in c 2b 2bthis pointer in cpp with examplec 2b 2b 28this 2a 29this pointer cppthis 3e c 2b 2b with pointerswhen is this pointer usedthis on c 2b 2bthis operator c 2b 2bthis 3e in cppcpp update this pointerthis eyword in c 2b 2bthis 3efunction in c 2b 2b 26 with this c 2b 2bc 2b 2b this 3d this 3ethis in cthis in c 2bthis a or this 3ea in c 2b 2bthis 3d 3e c 2b 2bwhat is 22this 22 pointer 3fin keyword in cppc 2b 2b what does this 2a dothis 3e c 2b 2bthis in cpptyat c 2b 2bc 2b 2b this pointera this pointer is found in methodsthis operator in c 2b 2buse of this pointer in c 2b 2bcpp this keywordc 2b 2b thatthis in c 2b 2b explain this pointer with examplethis in cpp languagethis 3e in c 2b 2bis this used in c 2b 2bthis c 2b 2bthis pointer in c 2b 2bthis c 2b 2b examplethis 28 29 c 2b 2bcpp thisthis ponter inc 2b 2bthis 3e keyword c 2b 2bkeyword this c 2b 2bcan we use this pointer in normal functionuse of this keyword in cppthis in c 2b 2bthis pointer program in c 2b 2bwhen to use the this keyword in c 2b 2bexplain this pointer using a suitable examplethis c 2b 2bkeyword this in c 2b 2bc 2b 2b this operatorc 2b 2b this keywordc 2b 2b 2b thisthis pointer comc 2b 2b this 27this 27 pointer iswhat is this this in c 2b 2busing this in c 2b 2bwhat does the this keyword do in c 2b 2bwhat is this operator 25this pointer is not found in what method javacan we write this pointer outside class in c 2b 2bc 2b 2b this this keyword in c 2b 2busing this pointer in c 2b 2bthis poiner in c 2b 2b classthis keyword in cppthis pointer represents the current class data members what is this in c 2bthis in c 2b 2b 5cis this pointer write a program to show this pointerthis in c 2b 2bexplain this pointer with suitable example in c 2b 2bwhat is this pointer in c 2b 2bthis keyword in cthis c 2b 2bthis 3e c 2b 2bwhat does this refer to in c 2b 2breturn class instance using this keyword in c 2b 2bthis in c 2b 2bwhat does this pointer program create 3fwhat is this keyword in c 2b 2bthis pointer isgeeks for geeks this pointer c 2b 2bthis c 2b 2b doingwhat is 22this pointer 22 in c 2b 2bthis pointer usageuse of this keyword in c 2b 2bhow to use this in c 2b 2bwhat does this in c 2b 2b meanc 2b 2b this 3ethis pointer 28 2athis 29 c 2b 2bc 2b 2b this 3dthis cppthis 3d c 2b 2bthis statements in c 2b 2bthis object in c 2b 2bcpp this 3euse of this in c 2b 2bthis c 2b 2b meaningthis 3ein c 2b 2bthis pointer c 2b 2bcpp thi0x6dfe28 meaning of this in c 2b 2bthis pointer is present in 3f object friend function main function member functionthis c 2b 2b 3dthis 3f operatorusing this keyword in c 2b 2bis pointer a keyword in c 2b 2bthis in c 2b 2b meaningreturning this pointer in c 2b 2bwhat does this 3e do in c 2b 2busing this operator in c 2b 2bin cpp this keyword isthis operatorin c 2b 2b 2c which of the following statements about the this pointerthis keyword in c 2b 2bthis function in c 2b 2bthis syntax in cppthis keyword in cpp