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

What does sksksk mean in text slang?

1534


What is encapsulation in simple terms?

537


How to improve object oriented design skills?

569


What is the difference between procedural programming and oops?

553


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?

1403






write a program using c++ to implement single contiguous memory mangement techniques.display the content of the main memory after yhe allocation of jobs and percentage of the wastage of the main memory

2759


What is Difeerence between List obj=new ArrayList(); and ArrayList obj=new ArrayList()?

2104


Can abstract class have normal methods?

611


What are the important components of cohesion?

553


What is polymorphism explain its types?

680


Write a program to sort the number with different sorts in one program ??

1915


Why is static class not inherited?

595


How to hide the base class functionality in Inheritance?

638


What is polymorphism explain?

691


What are two types of polymorphism?

611