Bloomberg LP Interview Question for Financial Software Developers






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

Virtual functions are used to extend the polymorphic behavior. You can use them when you want to call the implementation of the derived class member function using a base class pointer.
VPT:- every class has its own virtual function pointer table. It consist of its virtual functions in an organized way which helps compiler to determine which function to call at run time.

e.g
class A{
public:
virtual void print(){cout<<"A";}
};
class B:public A{
public:
void print(){cout<<"B";}
};
void main()
{
A* a;
B b;
a=&b;
a->print();
}

- Ashish October 17, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

http://www.go4expert.com/forums/showthread.php?t=8403

This would help us understand 4 byte vptr in a concise manner.

- ankushbindlish October 19, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

awesome!!!

- :D April 13, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

awesome!

- Kevin February 06, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

The actual location of the vptr pointer is not guaranteed since it's not a part of the C++ standard. It's up to C++ compiler how to implement polymorphic behavior. Virtual table is a common way of doing so.
When a virtual function is invoked the compiler replaces it with code like this:
(*pObj->vptr[idx])(arg);
where:
pObj - pointer the object
idx - the virtual function's unique id
arg - argument passed to the function
If the function is called through the object's name (not a pointer or reference) this call can be easily optimized so that vptr will not be used during run-time.

A good reference is Meyers 'More Effective C++ (35 New Ways...)', Item 24: Understand the costs of virtual functions

- Anonymous June 08, 2010 | 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