0 votes
in Computer by (50.4k points)

Explain the features of copy constructor.

1 Answer

+1 vote
by (50.4k points)
selected by
Best answer

The features of copy constructors are

  • copy constructor is a special type of parameterized constructor.
  • It is normally used to copy one object into another.
  • They are normally used to initialize object with values of already existing object.
  • Copy constructors should have at least one argument of the same class and must be passed as a constant reference type.
  • The copy constructor cannot be invoked explicitly but can be equated to an already existing object in the declaration itself.

For example:
x a1; _ _ _ default constructor invoked
X a2 = a1; _ _ _ copy constructor invoked.
The C++ compiler creates default copy constructor automatically.

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.