In C++, the "+" operator is overloaded (as member operator function) in user…

2022

In C++, the "+" operator is overloaded (as member operator function) in user defined class Matrix that adds two matrices and returns resultant matrix.

Which of the following is a signature of this operator function?

  1. A.

    Matrix operator + (Matrix A, Matrix B)

  2. B.

    Matrix operator + (Matrix B)

  3. C.

    Matrix + operator (Matrix A, Matrix B)

  4. D.

    Void + operator (Matrix B)

Attempted by 101 students.

Show answer & explanation

Correct answer: B

For a binary operator overloaded as a member function, the left operand is the object that calls the function and the right operand is the single explicit parameter. So A + B is internally treated as A.operator+(B). The function must return a Matrix because adding two matrices gives another Matrix. Therefore, the correct signature is Matrix operator+(Matrix B). Hence, Option B is correct.

Explore the full course: Uppsc Polytechnic Lecturer 2025 Cs