Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) When writing member funcations, if we have a class member with the same name

ID: 3771812 • Letter: 1

Question

1) When writing member funcations, if we have a class member with the same name as a parameter, how can we use the member name without any ambiguity ?

2) Given the following, what is the effect of each of the numbered sections?

const int func( const int x, float y) const

3) When choosing continers to use in our program,we have a choice of containers with O(n),O(n^2),O(log2 n), and O(n log2n). Put the container choices in order fron your first to your last choice and briefly tell me why you chose that order ?

Explanation / Answer

Ans1: take following example

Author::Author(string name, string email, char gender) {
   this->name = name;
   setEmail(email);


In this example, we use identifier name in the function's parameter, which crashes with the data member's identifier name. To differentiate between the two identifiers, we use the keyword this, which is a pointer to this instance. this->name refers to the data member; while name refers to the function's parameter.