Mastering C++: 2026 All-In-One Quiz – Ace 'Thinking in C++' with Comprehensive Practice!

Question: 1 / 565

What is the correct way to overload the '+' operator for a class as a member function?

Integer operator+(const Integer&);

const Integer operator+(const Integer&) const;

The operator+ should be overloaded as a const member function as it prevents modification of the current object's state. Option A is incorrect as the first parameter of an overloaded operator+ should be a reference to an object of the same class. Option C is incorrect as static member functions cannot be called on objects. Option D is incorrect as it returns a reference to an integer, whereas the operator+ should return the modified object. Therefore, option B is the correct way to overload the '+' operator for a class as a const member function.

Get further explanation with Examzify DeepDiveBeta

static Integer operator+(const Integer&);

Integer& operator+(const Integer&) const;

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy