WHEN A COPY CONSTER IS CALL ?

Answers were Sorted based on User's Feedback



WHEN A COPY CONSTER IS CALL ? ..

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

WHEN A COPY CONSTER IS CALL ? ..

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

WHEN A COPY CONSTER IS CALL ? ..

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

WHEN A COPY CONSTER IS CALL ? ..

Answer / muthu_tek

emp e;//default constr
emp e(10);//paramatrisized constr
emp e(e1);//copy constr

Is This Answer Correct ?    1 Yes 4 No

Post New Answer

More OOPS Interview Questions

what is the usage of clas templates

5 Answers  


What are the benefits of oop?

0 Answers  


write a c++ code to overload + and - for a stack class such that + provides push and - provides pop operation

1 Answers   College School Exams Tests, HCL, IBM, TCS,


WHY FUCTION OVERLOADING DOSENOT RETURN A RETEN TYPE

2 Answers  


What is cohesion in oop?

0 Answers  






WHAT IS THE DIFFERENCE BETWEEN OBJECT BASED & OBJECT ORIENTD PROGRAMMING LANGUAGE.(GIVE AT LIST 4 PIONT)

1 Answers   TCS,


Tell me the scenario,Where we can use interfaces or Abstract class.And What is the difference between interfaces and abstract class?

5 Answers  


What do you mean by multiple inheritance and multilevel inheritance? Differentiate between them.

2 Answers  


Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the maximum number of concurrent threads that the InnoDB plug-in can create.

1 Answers  


what is single inheritance?

18 Answers   IBM,


is java purely oop Language?

49 Answers   HCL, Infosys, TCS,


What is late bound function call and early bound function call? Differentiate.

2 Answers   Ness Technologies,


Categories