Q:

It is legal but redundant to refer to members through the this pointer. Discuss the pros and cons of explicitly using the this pointer to access members

0

It is legal but redundant to refer to members through the this pointer. Discuss the pros and cons of explicitly using the this pointer to access members. 

struct First { int memi; int getMem();
};
struct Second {
 int memi; int getMem();
};
First obj1;
Second obj2 = obj1; // error: obj1 and obj2 have different types

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Proc:

  - It is much more clear by using `this` to refer members.

  - The parameters in member function can have the same name as the data members if we use `this` pointer to refer data members.

Cons:

  - The code will look redundant.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now