Bloomberg LP Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
2
of 2 vote

search for vtable explaination on learncpp.com. They have a good explaination with diagrams.

Every class has a hidden member pointer called vptr. Along with each class there is a static table called Vtable. The vptr points to vtable. Everytime an object is created, the vptr in that object points to the vtable for the class. The vtable contains pointers to the virtual functions.
The derived class inherits the Base class and along with it gets the vptr. However this vptr points to vtable associated with the derived class.
When we invoke a virtual function through the Base pointer, it always goes to the vptr. The vptr for the Base class object points to the associated vtable. The vptr for the Derived class points to the vtable of the derived class. And therefore they accesses the correct functions.

- ACK December 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

vtable for class A vtable for class B
=============== =============
&A::Foo &B::Foo
================ ==============

- Ashish P April 01, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

the vtable will look like this

A's Table will have function foo() address as defined in A class
B's Table will have function foo() address as defined in B class

- newbee April 02, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

There wont be any vtable unless you instantiate an object

- sarray May 08, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I think the compiler will create VTable irrespective of object creation.

- subhransu5859 June 18, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

compiler dependent

- bbc July 03, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

why should there be a vtable for class A, its a abstract class.

- BJ September 15, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 2 vote

Class A is abstract. Abstract class cant be instantiated because they will not have vtable.
Class B will have vtable having address to B::foo

- kraj October 04, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

class A vtable points to base virtual function A::foo()
class B vtable points to most derived function which is B::foo() (if there is one), otherwise it points to base virtual function too

- Joanna8848 January 16, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

V table will has v ptr which points to function definition. For pure virtual function, v ptr points to NULL.

- Bharath Kumar Amarnath February 07, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

No Vtable for class A
vtable will be created only for class B which stores address of function B::foo()

- Amit W April 22, 2012 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More