Difference this.a & this->a

Hey guys!

In a function definition there is the possibility to

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Class
  {
    private:
      int a;
    public:
      Class(int);
  }


Class::Class(int num)
  {
    this.a = num;
    this->a = num;
  }



What is the difference and why might both work?
As I know "->" points to the object of the adress delivered by "this"

if
this = &ClassInstance
this->a (would point to a member of the object pointed to by this)

but if
this = &ClassInstance
this.a (would point to a member of a address...and a address doesnt has any member structures or something like that...its a plain number)

So why does both work? or at least compile?
Last edited on
> So why does both work? or at least compile?

this.a = num; does not compile.
http://coliru.stacked-crooked.com/a/209fbf3c149e99b1
http://rextester.com/POCE52051
Topic archived. No new replies allowed.