Solved

Draw the memory layout of a C++ class with two virtual functions

Posted on 2006-07-11
3
666 Views
Last Modified: 2008-01-09
It's an interview question. Any help is appreciated.

Thanks!
0
Comment
Question by:gromul
[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
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 17085339
See http://en.wikipedia.org/wiki/Virtual_method_table

Assuming

class foo {

public:

virtual void f1();
virtual void f2();

};

foo:
  +0: pointer to virtual method table of foo

Basically, it is only the pointer to the VTABLE if the class has no other (data) members - 4 bytes, that's it.

If you have

class foo {

public:

virtual void f1();
virtual void f2();

int n;
};

that'd be

  +0: pointer to virtual method table of foo
  +4: value of 'n'
0
 
LVL 11

Expert Comment

by:dbkruger
ID: 17085513
This is only a possible implementation, though it's extremely common, so I'd avoid saying this is THE layout.
It's conceivable that on some weird architecture they could do something else.

Good luck
0
 
LVL 4

Expert Comment

by:havman56
ID: 17097381
JKR  thanks for the link fom wikipedia

i learnt lot abt vtable  !!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

689 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