---
title: "Reference argument in copy constructor"
subject: "Object Oriented Programming"
chapter: 4
key: "semester_3/object_oriented_programming:copy-constructor-reference"
source: https://www.bctengineer.com/q/semester_3/object_oriented_programming/copy-constructor-reference
site: BCT Engineering
---

# Reference argument in copy constructor

Object Oriented Programming · Chapter 4: Objects and Classes

- Asked in: 2073 Shrawan, 3 marks
- Video: [Copy Constructor in C++](https://www.youtube.com/watch?v=KjBl6Wg20_4) — Neso Academy
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_3/object_oriented_programming/copy-constructor-reference
- Whole chapter: https://www.bctengineer.com/md/semester_3/object_oriented_programming/chapter-4

## Question

Why do you need a reference in the argument to the copy constructor?

## Short answer

The copy constructor's parameter must be a reference to avoid infinite recursion. Passing by value would require copying the argument using the copy constructor itself, leading to endless calls. A reference also avoids an extra copy, improving efficiency.

## Answer

A copy constructor has the form `ClassName(ClassName &obj)` or `ClassName(const ClassName &obj)`. The argument **must** be passed by reference, not by value.

#### Reason: infinite recursion

If the parameter were by value, `ClassName(ClassName obj)`:

1. To call the copy constructor, the argument must first be copied into the parameter `obj`.
2. Copying the argument into `obj` needs the copy constructor itself to be called.
3. That call again needs a copy for its own parameter, and so on without end.

This is endless recursion, so the compiler rejects it (error: invalid constructor, argument must be passed by reference).

```text
A b = a;  -> copy ctor(A obj = a)
              -> needs copy ctor to build obj
                  -> needs copy ctor ... (infinite)
```

#### Other benefits of a reference

- No temporary copy is made, so it is faster and uses less memory.
- It refers to the original object, so the data of the source is read directly.
- Using `const` prevents the source object from being modified accidentally, and allows copying from const objects and temporaries.

```cpp
class Point
{
    int x, y;
public:
    Point(int a, int b) { x = a; y = b; }
    Point(const Point &p) { x = p.x; y = p.y; }   // reference argument
};
Point p1(2, 3);
Point p2 = p1;     // calls copy constructor
```

## Check yourself

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

1. Why must the copy constructor argument be passed by reference?
   A. To save typing
   B. By value would require the copy constructor to copy the argument, causing infinite recursion
   C. To make it private
   D. To allow overloading
   Answer: B. Passing by value needs a copy to make the parameter, which calls the copy constructor again endlessly. (Key point: Why reference)

2. What does the compiler do with ClassName(ClassName obj)?
   A. Accepts it
   B. Rejects it as an invalid constructor
   C. Warns only
   D. Converts to reference
   Answer: B. The compiler errors because the argument must be passed by reference. (Key point: Compiler result)

3. What does const in const ClassName &obj add?
   A. Prevents modifying the source and allows copying from const objects and temporaries
   B. Makes it faster only
   C. Makes it static
   D. Allows recursion
   Answer: A. Const protects the source and permits copying from const objects/temporaries. (Key point: Const benefit)

## Related in Object Oriented Programming

- [Constructors: need and types](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Aconstructor-types) — Object Oriented Programming, chapter 4, asked 2×

## Related in other subjects

- [Field books and reference sketch](https://www.bctengineer.com/question.md?key=semester_3%2Fsurveying_i%3Afield-book-chain-survey) — Surveying I, chapter 3, asked 2×
- [Need of formulation; techniques for ToR](https://www.bctengineer.com/question.md?key=semester_7%2Fproject_engineering%3Aformulation-need-techniques-tor) — Project Engineering, chapter 2
- [Human need and Herzberg's hygiene theory](https://www.bctengineer.com/question.md?key=semester_7%2Forganization_and_management%3Aherzberg-human-need) — Organization and Management, chapter 8, asked 2×
- [Election algorithm need and example](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Aelection-scenario) — Distributed System, chapter 6, asked 2×
