Interview Question






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

Well you could, but when you took the address of an array element, it wouldn't look like other objects of that type. In theory the compiler could handle this, but in practice that would be a waste of the compiler writers' time.

- Anonymous August 03, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

@Anonymous : Did not get your pointer

- Crime_Master_GoGo August 03, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I mean did not get your point, could you explain in detail

- Crime_Master_GoGo August 03, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I mean did not get your point, could you explain in detail

- Crime_Master_GoGo August 03, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Basically

PolyClass one;

would look like [vtable][PolyClass's fields] and

PolyClass many[2];

would look like [vtable][PolyClass's fields][PolyClass's fields].

If we take the address &many[1], then it doesn't begin with a vtable; any code that uses it now has to become aware of its storage details.

- Anonymous August 03, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Crime_Master_GoGo, which company is this that you interviewed with?

- Anonymous August 04, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Its okay if was derived class object by itself that had virtual functions.

But imagine a case where Base * b = new Derived();

Here later when b is used, how would it knw which Vtable to use? that of Base class or derived class?
Cause later the same b can point to someother object of say Base class then.. or even later Derived2 class.

Hence each object has first allocation of Vtable pointer then other data.

So even if it later pointed by some other class pointer it would knw which object virtual functions are really valid.

- unicorn August 04, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Polymorphism is a run time feature. At run time the appropriate virtual function is invoked (using vptr & vtbl). For non-virtual functions the decision to invoke which function is made at compile time and hence the compiler does not generate any vtbl/vptr for it

- ss August 13, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Polymorphism is a run time feature. At run time the appropriate virtual function is invoked (using vptr & vtbl). For non-virtual functions the decision to invoke which function is made at compile time and hence the compiler does not generate any vtbl/vptr for it

- ss August 13, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Derive classes inherit *__vptr and point to it's own V table.
That is the reason why you can not have a static *__vptr...
Make sense??

- Brahma August 17, 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