WHEN A COPY CONSTER IS CALL ?
Answers were Sorted based on User's Feedback
Answer / preeti
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 A //With copy constructor
{
private:
char *name;
public:
A()
{
name = new char[20];
}
~A()
{
delete name[];
}
//Copy constructor
A(const A &b)
{
name = new char[20];
strcpy(name, b.name);
}
};
| Is This Answer Correct ? | 9 Yes | 0 No |
Answer / achal ubbott
Question on copy constructor is a classic one for an
interview. Since most modern day c++ compilers provide a
default copy constructor, most people don't get to try
hands over it. But in some cases it becomes mandatory to
define your own copy constructor and override the default
one.
So the places when CC is invoked are:-
1. calling a function e.g. void f(sample A);
2. creating an object from the existing object.
e.g. sample A=B; // here B is existing object.
3. When a function returns a copy of object.
e.g. sample f()
{
sample a;
return a;
}
| Is This Answer Correct ? | 2 Yes | 0 No |
Answer / vishwa
emp e;//default constr
emp e(10);//paramatrisized constr
emp e(e1);//copy constr
emp e = e1;//copy constr
| Is This Answer Correct ? | 2 Yes | 0 No |
What is the difference between a constructor and a destructor?
Can we define a class within the interface?
Can private class be inherited?
write a C++ program for booking using constructor and destructor.
What is the main feature of oop?
what about you? wahat is your object? introduce your self?
1 Answers Ajmal Perfumes, TCS,
How to execute business logic for only once ..?even though user clicks submit button multiple times by mistake..? (i disabled JavaScript)
what is the difference between javap and jad utility
why we call c++ is object oriented lanaguage
what is virtual function in c++
I have One image (means a group photo ) how to split the faces only from the image?............ please send the answer nagadurgaraju@gmail.com thanks in advace...
what is ns string? what is ns array?