As far as I know, one simple reason it takes reference to constant class type is to make sure that the object being copied is not modified in copy constructor. a object passed as non-const reference can be modified in copy construcor.
If the formal argument of copy constructor is made as "T obj" instead of usual "const T &obj", this simply involves copying the actual object in a temporary object(created on the function stack), which again requires copy constructor. In a way this is a recursive call. On Wed, Jul 21, 2010 at 9:08 AM, mallesh <mallesh...@gmail.com> wrote: > In C++ Why is it that copy constructor uses only reference as > parameter and not the actual class? > I was given a hint that it has got something to do with stack. I think > it has got something to do with reentrant functions. > > In C also., I think the same thing happens when we pass struct as > parameter to a function, instead of copying the whole structure on to > stack, it takes struct variable's address. > > Can you please explain why this is so? > > -Thanks and regards, > Mallesh > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.