2 Replies - 646 Views - Last Post: 20 February 2009 - 06:20 PM Rate Topic: -----

#1 kristi.ambrose  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 20-February 09

What happens to the member function in the class when copy...

Posted 20 February 2009 - 02:44 AM

Hi everyone,

What happens to the member function in the class when copy constructor is invoked?

Thanks
--------------------------------
web site design and maintenance
Is This A Good Question/Topic? 0
  • +

Replies To: What happens to the member function in the class when copy...

#2 GWatt  Icon User is offline

  • member icon

Reputation: 274
  • View blog
  • Posts: 3,072
  • Joined: 01-December 05

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.
Was This Post Helpful? 0
  • +
  • -

#3 boblied  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 66
  • Joined: 20-February 09

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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1