NaukriSalah: Can a copy constructor accept an object of the same class as parameter, instead of reference of the object? - NaukriSalah

Jump to content

Can a copy constructor accept an object of the same class as parameter, instead of reference of the object?

#1 Guest_vikas_*

  • Group: Guests

Posted 11 December 2009 - 08:48 AM

Can a copy constructor accept an object of the same class as parameter, instead of reference of the object?


No. It is specified in the definition of the copy constructor itself. It should generate an error if a programmer specifies a copy constructor with a first argument that is an object and not a reference.
0

#2 Guest_Rmn_*

  • Group: Guests

Posted 14 December 2009 - 09:48 AM

View Postvikas, on 11 December 2009 - 08:48 AM, said:

Can a copy constructor accept an object of the same class as parameter, instead of reference of the object?


No. It is specified in the definition of the copy constructor itself. It should generate an error if a programmer specifies a copy constructor with a first argument that is an object and not a reference.



Agreed- Question more clearely is,weather we can pass by value rather than reference in a copy constructor. No we can not pass data by value in a copy constructor.Since by its defination it must except a reference to copy both the locations byte by byte.
0

#3 User is offline   Raj Malhotra Icon

  • Newbie
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 14-December 09

Posted 14 December 2009 - 12:18 PM

Thanks for the above answer.
0



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users