0
    Rectangle::Rectangle(Rectangle &r)
{
 this.length=r.length;
 this.breadth=r.breadth;
}

I used this. instead of this-> and it gives error

[Error] request for member 'breadth' in '(Rectangle*)this', which is of pointer type 'Rectangle*' (maybe you meant to use '->' ?)

So does this mean class are sort of like Pointers? or I might be lacking some concepts so please help me to understand.

csAshish
  • 5
  • 3
  • Because `this` is a pointer. – Retired Ninja Aug 15 '22 at 05:30
  • `this` in c++ in a pointer. And `->` is the way to access members of objects ponited by the pointer. – wohlstad Aug 15 '22 at 05:31
  • Because in order to write `this.` and have it work, `this` would have to be a reference; and the `this` feature was added to the language before references were. – Karl Knechtel Aug 15 '22 at 05:37
  • 1
    "So does this mean class are sort of like Pointers?" It means that `this` **is** a pointer, which *points to the instance of* the class you're working with in that member function. Classes and pointers are completely different and unrelated things. – Karl Knechtel Aug 15 '22 at 05:38

1 Answers1

0

According to docs:

The expression this is an rvalue (until C++11)a prvalue (since C++11) expression whose value is the address of the implicit object parameter

So, this here is a pointer that point to the address that store value of the instance of class Rectangle.

houtaru
  • 16
  • 3