Answer Posted / sudha
A copy constructor is a special constructor in the C++
programming language used to create a new object as a copy
of an existing object.
There are 3 important places where a copy constructor is
called.
When an object is created from another object of the same
type
When an object is passed by value as a parameter to a
function
When an object is returned from a function
class B //With copy constructor
{
private:
char *name;
public:
B()
{
name = new char[20];
}
~B()
{
delete name[];
}
//Copy constructor
B(const B &b)
{
name = new char[20];
strcpy(name, b.name);
}
};
| Is This Answer Correct ? | 6 Yes | 0 No |
Post New Answer View All Answers
Why is it so that we can have virtual constructors but we cannot have virtual destructors?
What is polymorphism what are the different types of polymorphism?
What is overloading and its types?
class type to basic type conversion
How do you answer polymorphism?
What type of loop is a for loop?
What is the renewal class?
Where You Can Use Interface in your Project
Why is polymorphism used?
What is object and class in oops?
What is class in oop with example?
Write a java applet that computes and displays the squares of values between 25 and 1 inclusive and displays them in a TextArea box
INSTANCE FIELDS DECLARED private ARE ACCESSIBLE BY THE METHODS ONLY.CAN WE CHANGE THE private FIELD OF AN OBJECT IN A METHOD OF SOME OTHER OBJECT OF THE SAME CLASS?
What are the components of marker interface?
What is Difeerence between List obj=new ArrayList(); and ArrayList obj=new ArrayList()?