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
What is the important feature of inheritance?
What is multilevel inheritance in oop?
What is a class oop?
Can enum be null?
What is polymorphism and why is it important?
Get me a number puzzle game-program
Whats is abstraction in oops?
What is oops in simple words?
c++ program to swap the objects of two different classes
What is class in oop with example?
What is polymorphism oop?
What is inheritance in simple words?
What is the use of oops?
How to call a non virtual function in the derived class by using base class pointer
What is overloading in oops?