x

Choose Country Code

x

Direction

x

Ask a Question

  • Ask a Question
  • Scan a Question
  • Post MCQ
  • Note: File extension must be of jpg, jpeg, png, bmp format and file size must not exceed 5 MB
x

Ask a Question

x

x
x
x
Hire a Tutor

Answers and Solutions

What's Your Question?
Answer

Copy constructor, the argument to the function is of same class type, while in overloaded assignment operator function, the argument can be of any type.

Answer
copy constructor is used to initialize a previously uninitialized object from some other object's data. A(const A& rhs) : data_(rhs.data_) {} An assignment operator is used to replace the data of a previously initialized object with some other object's data. A& operator=(const A& rhs) {data_ = rhs.data_; return *this;}
Answer

in copy constructor, the argument to the function is of same class type, while in overloaded assignment operator function, the argument can be of any type.

Answer
  • Genrally arguments of a constructor can be of any-type except of its own. But it can accept a 'reference' of its own. which is called a copy constructor.  CC is called only in the folloing cases. 

                 sampleclass sc1, sc4; sampleclass sc2(sc1); sampleclass sc3 = sc2;

                 sc4 = sc1;  // here it is called overloaded assignment operator. I guess I answered you.

Post Answer and Earn Credit Points

Get 5 credit points for each correct answer. The best one gets 25 in all.

Post Answer