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

1.) What are the differences in the function calls between the four member funct

ID: 3786313 • Letter: 1

Question

1.) What are the differences in the function calls between the four member functions of the Shape class below?

void Shape::member(Shape s1, Shape s2);

void Shape::member(Shape *s1, Shape *s2);

void Shape::member(Shape& s1, Shape& s2) const;

void Shape::member(const Shape& s1, const Shape& s2);

void Shape::member(const Shape& s1, const Shape& s2) const;

also,

Given the following definition of Value::operator=

1) Value& operator=(const Value &rhs)

2) {

3) if (&rhs == this)

4) return *this;

5) v = rhs.v;

6) return *this;

7) } Explain the meaning of '&' on line 1 and on line 3 separately.

Many thanks!

Explanation / Answer

1)

void Shape::member(Shape s1, Shape s2); ---- This is pass by value

void Shape::member(Shape *s1, Shape *s2); ---- This is pass by pointer

void Shape::member(Shape& s1, Shape& s2) const; ---This is pass by reference

void Shape::member(const Shape& s1, const Shape& s2); --- This is pass by constant reference

void Shape::member(const Shape& s1, const Shape& s2) const; ---This is pass by constant reference but also the function is constant too

2)