Skip to content

Commit 48212ad

Browse files
committed
the "this pointer"
1 parent 9b50cb1 commit 48212ad

File tree

1 file changed

+34
-0
lines changed
  • Learn_CPP_Programming_Deep_Dive/Section 11 OOP/Using_the_this_pointer

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
/* the this pointer is useful to refer to members of the current object */
6+
7+
class Rectangle
8+
{
9+
private:
10+
int length;
11+
int breadth;
12+
13+
public:
14+
Rectangle(int length, int breadth)
15+
{
16+
this->length = length;
17+
this->breadth = breadth;
18+
}
19+
20+
int area()
21+
{
22+
return length * breadth;
23+
}
24+
};
25+
26+
27+
int main(void)
28+
{
29+
Rectangle r1(15,45);
30+
31+
cout<<"The area is "<<r1.area()<<endl;
32+
33+
return 0;
34+
}

0 commit comments

Comments
 (0)