tell about copy constructor

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


Please Help Members By Posting Answers For Below Questions

Can we define a class within the interface?

551


What is coupling in oops?

593


What is super in oop?

595


What is the purpose of polymorphism?

675


What is meant by oops concept?

608






What are oops methods?

566


What is difference between pop and oop?

603


Which type does string inherit from?

614


What is overloading in oop?

572


is there any choice in opting subjects like 4 out of 7

1727


Can we have inheritance without polymorphism?

608


They started with the brief introduction followed by few basic C++ questions on polumorphism, inheritance and then virtual functions. What is polymorphims? How you will access polymorphic functions in C? How virtual function mechanism works?

1393


What does no cap mean?

590


Why is static class not inherited?

593


Can a destructor be called directly?

599