Solved

Objects

Posted on 2003-11-18
6
270 Views
Last Modified: 2010-04-01
1) Do member functions occupy space in objects?
0
Comment
Question by:LeelaSwamy
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
  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 …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

744 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now