Solved

Objects

Posted on 2003-11-18
6
274 Views
Last Modified: 2010-04-01
1) Do member functions occupy space in objects?
0
Comment
Question by:LeelaSwamy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 50 total points
ID: 9770363
Only if they are virtual.
0
 
LVL 9

Expert Comment

by:jhshukla
ID: 9774041
when you compile a program, a "symbol table" is created that has information for each datatype used in the program, including basic types. (int, char ...) the information for global functions and member functions of classes is also stored in the same table for later use.

functions are part of the class not the variable. same thing with static members of the class except for one difference. static members can be accessed without actually creating an object but non-static functions have to be called using concrete objects.

so the answer is NO.
0
 
LVL 9

Expert Comment

by:jhshukla
ID: 9774049
yes, and only if they are virtual.
0
 
LVL 2

Expert Comment

by:MirkoLMV
ID: 9801039
The answer is not simple, because the question is not simple.
There is no consensus on objects implementation in C++, just common aspects and more or less differences between various compilers. However, we can consider that intimate details of relevance for C++ programmers are common to the most implementations, and the differences are important just for the restraint circles of compiler developers. (Compiler development is a quite definite specialty in programing).
The code of a member function  appears just in a single place in a program, related to the class object (the object which is employed by the program as a template for creating instance objects of the class). Each instance object has access to the same piece of code, and the this pointer has some importance in this mechanism. It is suggested a very limited space expense for each instance object, regardless of the number of member functions.
For virtual member functions there is also no code duplication at all. There is a virtual methods table (VMT or vtable) within the class objects, and every instance object has just a special pointer (vpointer) to the virtual methods table.

Good luck !
0
 
LVL 9

Expert Comment

by:tinchos
ID: 10249278
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: AlexFM {http:#9770363}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question