---
title: "Overloading via member and non-member function"
subject: "Object Oriented Programming"
chapter: 5
key: "semester_3/object_oriented_programming:member-vs-nonmember-overload"
source: https://www.bctengineer.com/q/semester_3/object_oriented_programming/member-vs-nonmember-overload
site: BCT Engineering
---

# Overloading via member and non-member function

Object Oriented Programming · Chapter 5: Operator Overloading

- Asked in: 2069 Chaitra, 3 marks
- Video: [13.5 Operator Overloading member vs. non-member functions](https://www.youtube.com/watch?v=NDBVrzZ3Npw) — cjumpdotcom
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_3/object_oriented_programming/member-vs-nonmember-overload
- Whole chapter: https://www.bctengineer.com/md/semester_3/object_oriented_programming/chapter-5

## Question

How can you overload operators using member function and non-member function?

## Short answer

Member functions: left operand is this; binary takes one argument, unary none. Non-member (friend): no this pointer; binary takes two arguments, unary one. Use member when left operand is class type; use friend for mixed types (e.g., cout << obj) or built-in left operand. =, [], (), -> must be members.

## Answer

An operator can be overloaded either as a **member function** of the class or as a **non-member (usually friend) function**.

#### Using a member function
The left operand is the calling object (`this`). A binary operator takes one argument; a unary operator takes none.

```cpp
class Point {
    int x, y;
public:
    Point(int a = 0, int b = 0) { x = a; y = b; }
    Point operator+(Point p) {              // a + b  ->  a.operator+(b)
        return Point(x + p.x, y + p.y);
    }
};
```

#### Using a non-member function
It is declared outside the class and normally made a `friend` so it can reach private data. A binary operator takes two arguments; a unary operator takes one.

```cpp
class Point {
    int x, y;
public:
    Point(int a = 0, int b = 0) { x = a; y = b; }
    friend Point operator+(Point p, Point q);   // a + b -> operator+(a, b)
};
Point operator+(Point p, Point q) {
    return Point(p.x + q.x, p.y + q.y);
}
```

**When to use which:**
- Member function: when the left operand is always an object of the class. `=`, `[]`, `()`, `->` must be members.
- Non-member function: when the left operand is a built-in type or another class (e.g. `5 + obj`, or `cout << obj`).

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. How many arguments does a unary member operator take?
   A. 0
   B. 1
   C. 2
   D. 3
   Answer: A. The object itself is the operand via this. (Key point: Member arguments)

2. How many arguments for a binary non-member operator?
   A. 1
   B. 2
   C. 0
   D. 3
   Answer: B. Both operands are passed explicitly. (Key point: Non-member binary)

3. When must you use a non-member?
   A. Left operand is a built-in type, e.g. 5 + obj
   B. Using a unary operator
   C. Operator is =
   D.  Operator is []
   Answer: A. A member requires an object of the class on the left. (Key point: When non-member)

## Related in Object Oriented Programming

- [Function overloading; new/delete average program](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Afunction-overloading-new-delete-average) — Object Oriented Programming, chapter 3
- [Binary operator member function one argument](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Abinary-member-one-argument) — Object Oriented Programming, chapter 5
- [Default arguments and function overloading](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Adefault-args-function-overloading) — Object Oriented Programming, chapter 3, asked 5×
- [Function overriding versus overloading](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Afunction-overriding-vs-overloading) — Object Oriented Programming, chapter 6, asked 2×
- [Need of template; function template overloading](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Awhy-template-function-overloading) — Object Oriented Programming, chapter 9
- [Static data member and member function](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Astatic-member-function) — Object Oriented Programming, chapter 4, asked 3×

## Related in other subjects

- [Global vs local; & and * operators](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Aglobal-local-ampersand-star) — Computer Programming, chapter 3
- [Operators and expected energy in a well](https://www.bctengineer.com/question.md?key=semester_3%2Felectrical_engineering_material%3Aoperators-expected-energy-well) — Electrical Engineering Material, chapter 1
- [Need for non-uniform quantization; SQNR of DM](https://www.bctengineer.com/question.md?key=semester_6%2Fcommunication_systems%3Anonuniform-quantization-dm-sqnr) — Communication Systems, chapter 4, asked 2×
- [Is recursion slow; recursive vs non-recursive](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Arecursion-slow-compare) — Data Structure and Algorithm, chapter 5
