?
Solved

Objects

Posted on 2003-11-18
6
Medium Priority
?
278 Views
Last Modified: 2010-04-01
1) Do member functions occupy space in objects?
0
Comment
Question by:LeelaSwamy
5 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 200 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.
Suggested Courses

807 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