Hi everyone,
What happens to the member function in the class when copy constructor is invoked?
Thanks
--------------------------------
web site design and maintenance
2 Replies - 541 Views - Last Post: 20 February 2009 - 06:20 PM
#1
What happens to the member function in the class when copy...
Posted 20 February 2009 - 02:44 AM
Replies To: What happens to the member function in the class when copy...
#2
Re: What happens to the member function in the class when copy...
Posted 20 February 2009 - 03:08 AM
Nothing. Calling the copy constructor does not change the functions.
#3
Re: What happens to the member function in the class when copy...
Posted 20 February 2009 - 06:20 PM
This used to confuse me when I first started using C++, too. Because of the way that the class is written in source code, it looks like every object should carry along its data and functions as part of the object, like a little bundle of data+functions. But that's not what happens. Every object has to have its own copy of member data, but the member functions are identical for every object of the class. What the compiler does is place the object code for the member functions off to the side, just like any ordinary function, and every object of the class shares the same member function code.
Each object that is created is just a bundle of data, not including the functions. When the object is copied, only its data needs to be copied.
Each object that is created is just a bundle of data, not including the functions. When the object is copied, only its data needs to be copied.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote



|