Copy Constructor
-
Hi, can anyone please help me out in understanding COPY CONSTRUCTOR..please clarify me on the following questions.. 1. What a COPY CONSTRUCTOR actually does and when it is used.. 2. Please let me know as when we go about writing our own COPY CONSTRUCTORS(though system provides one by default).. 3. What a assigment operator does and in what way is it different from COPY CONSTRUCTOR.. if there are any interesting materials on these topics do let me know as I am getting much confused on the usage of these concepts.. Thanks In Advance
-
Hi, can anyone please help me out in understanding COPY CONSTRUCTOR..please clarify me on the following questions.. 1. What a COPY CONSTRUCTOR actually does and when it is used.. 2. Please let me know as when we go about writing our own COPY CONSTRUCTORS(though system provides one by default).. 3. What a assigment operator does and in what way is it different from COPY CONSTRUCTOR.. if there are any interesting materials on these topics do let me know as I am getting much confused on the usage of these concepts.. Thanks In Advance
Check this link http://www.fredosaurus.com/notes-cpp/oop-condestructors/copyconstructors.html SaRath
-
Hi, can anyone please help me out in understanding COPY CONSTRUCTOR..please clarify me on the following questions.. 1. What a COPY CONSTRUCTOR actually does and when it is used.. 2. Please let me know as when we go about writing our own COPY CONSTRUCTORS(though system provides one by default).. 3. What a assigment operator does and in what way is it different from COPY CONSTRUCTOR.. if there are any interesting materials on these topics do let me know as I am getting much confused on the usage of these concepts.. Thanks In Advance
Subramaniam wrote:
1. What a COPY CONSTRUCTOR actually does and when it is used..
It is used to copy the contents of the Existing object to new born object
Subramaniam wrote:
2. Please let me know as when we go about writing our own COPY CONSTRUCTORS(though system provides one by default)..
When you want to give the limited access to your object's from copy for e.g by making it private only member functions can access and public access denied
Subramaniam wrote:
3. What a assigment operator does and in what way is it different from COPY CONSTRUCTOR..
Assignment operator initialises the existing object by another existing object Copy constructer initialises the new born object by existing object for e.g CDemo d2; CDemo d=d2; //copy constructer CDemo d1(d2); //copy constructer CDemo d3; d3=d2; //Assignment operator Knock out 't' from can't, You can if you think you can :cool:
-
Subramaniam wrote:
1. What a COPY CONSTRUCTOR actually does and when it is used..
It is used to copy the contents of the Existing object to new born object
Subramaniam wrote:
2. Please let me know as when we go about writing our own COPY CONSTRUCTORS(though system provides one by default)..
When you want to give the limited access to your object's from copy for e.g by making it private only member functions can access and public access denied
Subramaniam wrote:
3. What a assigment operator does and in what way is it different from COPY CONSTRUCTOR..
Assignment operator initialises the existing object by another existing object Copy constructer initialises the new born object by existing object for e.g CDemo d2; CDemo d=d2; //copy constructer CDemo d1(d2); //copy constructer CDemo d3; d3=d2; //Assignment operator Knock out 't' from can't, You can if you think you can :cool:
-
Subramaniam wrote:
1. What a COPY CONSTRUCTOR actually does and when it is used..
It is used to copy the contents of the Existing object to new born object
Subramaniam wrote:
2. Please let me know as when we go about writing our own COPY CONSTRUCTORS(though system provides one by default)..
When you want to give the limited access to your object's from copy for e.g by making it private only member functions can access and public access denied
Subramaniam wrote:
3. What a assigment operator does and in what way is it different from COPY CONSTRUCTOR..
Assignment operator initialises the existing object by another existing object Copy constructer initialises the new born object by existing object for e.g CDemo d2; CDemo d=d2; //copy constructer CDemo d1(d2); //copy constructer CDemo d3; d3=d2; //Assignment operator Knock out 't' from can't, You can if you think you can :cool:
Thanks. can you be more elaborate on the following comments given by you.. "When you want to give the limited access to your object's from copy for e.g by making it private only member functions can access and public access denied" Thanks
-
Thanks. can you be more elaborate on the following comments given by you.. "When you want to give the limited access to your object's from copy for e.g by making it private only member functions can access and public access denied" Thanks
Subramaniam wrote:
"When you want to give the limited access to your object's from copy for e.g by making it private only member functions can access and public access denied"
See the following example
class CDemo
{
int i;
CDemo(CDemo &b)
{
i=b.i;
};
public:CDemo& operator=(const CDemo &b) { this->i=b.i; return \*this; }; CDemo(){}; //public constructer CDemo test() { return \*this; }
};
int main(int argc, char* argv[])
{
CDemo c;
c=c.test();
CDemo c1(c); //not allowed
CDemo c2=c; //even this also not allowed.
return 0;
}With this we can prevent public from making copy of the objects only class members are allowed to make such coping :) Knock out 't' from can't, You can if you think you can :cool:
-
Jax_qqq wrote:
Hei Laxman r u giving Interview or what...
No, i am learning C++ with CP. :) Knock out 't' from can't, You can if you think you can :cool:
-
Jax_qqq wrote:
Hei Laxman r u giving Interview or wha
Hope so!... humm.. i am waiting for your answer
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV