Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Abstract class, copy constructor

Does it make sense to define a copy constructor / operator = in class having pure virtual method or only in derived classes?

like image 349
Johny Avatar asked Apr 08 '11 09:04

Johny


People also ask

What is the copy constructor of a class?

A copy constructor is a member function that initializes an object using another object of the same class. In simple terms, a constructor which creates an object by initializing it with an object of the same class, which has been created previously is known as a copy constructor.

Can abstract class have copy constructor?

Yes you should. Rules of having your own implementations for copy constructor, copy assignment operator and destructor for a Class will apply to even an Abstract Class.

What is the use of copy constructor?

A copy constructor is a member function of a class that initializes an object with an existing object of the same class. In other words, it creates an exact copy of an already existing object and stores it in a new object.

What does copy constructor do in Java?

A copy constructor in a Java class is a constructor that creates an object using another object of the same Java class. That's helpful when we want to copy a complex object that has several fields, or when we want to make a deep copy of an existing object.


1 Answers

like normal classes: yes, if you have a specific implementation need.

like image 197
justin Avatar answered Oct 05 '22 11:10

justin