Solved

Objects

Posted on 2003-11-18
6
273 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

733 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