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
Can we define a class within the interface?
What is coupling in oops?
What is super in oop?
What is the purpose of polymorphism?
What is meant by oops concept?
What are oops methods?
What is difference between pop and oop?
Which type does string inherit from?
What is overloading in oop?
is there any choice in opting subjects like 4 out of 7
Can we have inheritance without polymorphism?
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?
What does no cap mean?
Why is static class not inherited?
Can a destructor be called directly?