answersLogoWhite

0

What is cloning in c plus plus?

Updated: 8/20/2019
User Avatar

Wiki User

12y ago

Best Answer

Cloning simply means returning a copy of an existing object.

When we work with base classes, it helps to include virtual methods that allow us to create new instances of derived objects as well as base objects, even when we don't know the exact type of those derived classes beforehand. We could use runtime information to determine the exact type, but its costly and ultimately defeats the purpose of polymorphism.

By convention, the virtual methods are called Create(), Clone() and Copy().

Create() is the same as calling the default constructor of the class.

Clone() is the same as calling the copy constructor of the class.

Copy() is the same as calling the assignment operator of the class.

It should be noted that the actual copy constructor and assignment operators should both call the Copy() method while the Create() method should also be overloaded to cater for all other construction overloads besides the default constructor.

With these methods in place, it becomes possible for base classes to implement much of the functionality that would otherwise only be possible by accessing costly runtime information, or by duplicating code in all derived classes, which quickly becomes a maintenance nightmare.

The methods can also be used in abstract classes, but they must be declared pure-virtual since you cannot create instances of an abstract class.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is cloning in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Who ivented cloning?

Cloning was invented by Carter D. and Dallas C. on a late monday night.lol whoever put that is an idiot, don't listen to them.


What is b plus b plus b plus c plus c plus c plus c?

b+b+b+c+c+c+c =3b+4c


What is c plus c plus 2c plus c plus c equal?

c + c + 2c + c + c = 6c


B plus b plus b plus c plus c plus c plus c equals?

b + b + b + c + c + c + c = 3b + 4c


Symplify c plus c plus c plus c?

4c


What are the cons of cloning?

C. Placing an adult nucleus in a cell without a nucleus.


What is c plus c plus c plus c plus c?

c + c + c + c + c = 5 * c.


Primary and secondary key in c and c plus plus?

There are no "primary and secondary keys" in c and c plus plus.


What is c plus C plus C answer in algebra?

3c


What is the different between turbo c plus plus and unix c plus plus?

There is no such thing as 'unix C++'.


What to Do if Macros does not exist in C and C plus plus?

They do exist in C and C++.


If A equals 4.0GPA than C plus equals?

C plus is between 3 and 3.2. C = 75% 0% < Plus < 5% 75%+0% < C Plus < 75%+5% 75 < C Plus < 80% 75%*4 < C Plus < 80% * 4 (3/4)*4 < C Plus < (4/5) * 4 3 < C Plus < 16/5 3 < C Plus < 3.2