By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,148 Members | 1,282 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,148 IT Pros & Developers. It's quick & easy.

How objects are sharing the member function???

P: n/a
Hi All,

In C++, all the objects of a single class having separate data members.
While all those objects are sharing a single copy of the member
function.

If it is the case where these member functions will be stored? whether
it's on the text section of the process memory?

Can any one explain this, how it works?

Regards,
Pearl

Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

ms******@gmail.com wrote:
Hi All,

In C++, all the objects of a single class having separate data members. While all those objects are sharing a single copy of the member
function.

If it is the case where these member functions will be stored? whether it's on the text section of the process memory?

Can any one explain this, how it works?

Regards,
Pearl


The place where the functions are stored is immaterial and is left to
the implementation. Even in inheritance the derived class and the
parent class will share the same function if it is not a virtual
function and if it is not overloaded.

Regards
Shan

Jul 23 '05 #2

P: n/a
You can view a C++ object as a C structure and a set of C functions
that take in a pointer to the structure as their first parameter.

Thus :
class A
{ int a;
int b;
void HandleOperation(int opcode); }

is equivalent to the following in C code:

struct A
{ int a; int b; };

void HandleOperation(A *this, int opcode);

The following articles would make this even more clear:

http://www.eventhelix.com/RealtimeMa...erformance.htm
http://www.eventhelix.com/RealtimeMa...rformance2.htm

Deepa
--
EventStudio 2.5 - http://www.EventHelix.com/EventStudio
Enter model in plain text;generate sequence diagram in PDF/Word

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.