Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


tell about copy constructor

Answers were Sorted based on User's Feedback



tell about copy constructor..

Answer / 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

tell about copy constructor..

Answer / madhu

Basic thing, copy constructor will be called whenever a copy
is made. and copy constructors are called when:
1. create a new object using existing object.
2. When is returning to caller.
3. When an object is passed by value as a parameter to a
function

Basically a default copy constructor will be created which
does bitwise copy also know as shallow copy.
This will become a problem when we are dealing with dynamic
memory allocation for variables and leads to dangling pointer.
To overcome we have to override by deep copy.

Is This Answer Correct ?    3 Yes 0 No

tell about copy constructor..

Answer / achal ubbott

e.g. Let there be a class

class Sample
{

};
suppose in main() you do like here

Sample obj1;
Sample obj2 = obj1; // Copy cons called here.
// then you call a function like this

fun(obj1); //Copy cons called here.

Is This Answer Correct ?    1 Yes 1 No

Post New Answer

More OOPS Interview Questions

What is virtual function?where and when is it used?

2 Answers   Sitel,


How compiler selects(internally) required overridden function in inheritance?

2 Answers   CSC, Infinite Computer Solutions,


design class for linked list and include constructor,destructor,insert option. struct node { int node; struct node &ptr; }

1 Answers   HSBC,


Contrast OOP and SOA. What are tenets of each?

1 Answers   Siebel Systems, Wipro,


what is overloading and overriding?

7 Answers  


What does and I oop and sksksk mean?

0 Answers  


Explain polymorphism? What r the types of polymorphism? pls give examples?

4 Answers   HCL,


What is an advantage of polymorphism?

0 Answers  


Base class has two public data members. How can i derive a new class with one datamember as public and another data member as private?.

2 Answers  


#include <iostream> using namespace std; struct wow { int x; }; int main() { wow a; wow *b; a.x = 22; b = &a; a.x = 23; cout << b->x; return 0; }

1 Answers  


why in java first invoke public static void main(String args[]) method????Why not public static void method1(String args[])??

1 Answers  


What is a class oop?

0 Answers  


Categories