Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Yesterday I had a terrible experience in an interview.

Interviewer asked me about pure virtual function. I said, It may or may not have definition in base class, but derived classes should provide definition unless they also want to be abstract class.

But interviewer kept on asking that "Can pure virtual have definition !!! ???"... I said yes.

Again he said "Pure ?"

I said yes. It is allowed, derived classes can explicitly call that function if they want that particular behavior.

He sent me out. I am sure that he doesn't know the fact that pure virtual function can have definition.

How to deal with this kind of Interviewers ?

After asking 2nd time, should i lie that it can't have definition ? :)

Or i should stick to my words and loose the job opportunity ?

share|improve this question
45  
You should contact them with an example of a pure virtual function with a definition, so they know. –  GManNickG Jan 9 '11 at 7:14
17  
GMan's suggestion is an excellent idea. You'll likely impress the interviewer that you cared enough about the job to follow up whether he believes you or not. And if you teach him something in as non-confrontational way as possible, well that should only encourage him/her to think more highly of you as a developer. Still a tough decision whether you want to work there or not, though. –  Cody Gray Jan 9 '11 at 7:19
42  
But do you really want to work for such people? –  leppie Jan 9 '11 at 7:22
25  
One of my interviewer had asked me question that involved this expression arr[++i] = i. And when I said this invokes undefined-behavior and told him about sequence points, he was speechless for a moment, and then his facial expression and his further questions made me believe that he never even heard these terms before! –  Nawaz Jan 9 '11 at 7:45
9  
Do consider that interviewers are often selected not for their technical skill but their ability to assess the interviewee's communication talents. Technical skill is easily gauged, ability to be productive and fit in a team is not. Sounds to me you got plenty of opportunity to adapt your view and to explain your insistence to not do so but accomplished neither. That didn't go well. –  Hans Passant Jan 9 '11 at 8:01
show 10 more comments

migrated from stackoverflow.com Jan 9 '11 at 8:27

This question came from our site for professional and enthusiast programmers.

closed as not constructive by Yannis Rizos Mar 7 '12 at 9:09

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

11 Answers

up vote 76 down vote accepted

No. And you should thank your lucky stars that you got missed by that particular bullet. Working for people who refuse to admit that they might not know everything, and refuse to learn from others, is a VERY unpleasant experience.

share|improve this answer
5  
+1. A good one. –  user8685 Jan 9 '11 at 8:40
15  
+1. Interviewers give you an impression of the company. –  Programming Enthusiast Jan 9 '11 at 9:12
5  
More precisely the job interview process works both ways. While the company is judging me as an employee, I'm judging them as an employer. Many are found wanting. –  JUST MY correct OPINION Jan 9 '11 at 12:14
    
Indeed. During my phone interview for a position a few days ago, the interviewer asked for an example of something that would demonstrate the knowledge of someone familiar with the language they're using. A question about it was added at the last minute to the in-person interview. I know these guys and I know they're great devs, so I think I want to work with them. :) –  greyfade Jan 10 '11 at 19:01
add comment

You could've explained how to declare a pure virtual function that has an implementation.

In fact, I wish you would here because I'm not familiar with how to do that either.

share|improve this answer
5  
You just declare the function pure virtual and then provide an implementation. It's a pretty uncommon practice to do this, but in "Effective C++, 3rd Edition" Scott Meyers describes a few scenarios where it's useful. In particular, since the function is pure virtual, the class it's declared in is abstract, but because it has an implementation, it gives subclasses a default implementation they can explicitly choose to use if they want. –  templatetypedef Jan 9 '11 at 7:11
1  
Well, that doesn't explain HOW it's done. If anyone is interested, check out en.wikipedia.org/wiki/…. At any rate, I still think explaining how to do it would've been the best response. –  Jonathan Wood Jan 9 '11 at 7:16
1  
+1 - and I second your second line. Worse, unless I was in an exceptionally "but sometimes on wrong" mood, I would have sided with the interviewer. The trouble is that you can only second guess your beliefs to a certain degree, or else you effectively end up knowing nothing. –  Steve314 Jan 9 '11 at 7:17
1  
@Steve314: Heh, I find the older I get, the more I'm open to being wrong. There's always someone who knows more than me. :-) –  Jonathan Wood Jan 9 '11 at 7:19
    
@Jonathon - yes, but without a 100% accurate indication of how confident I should be about all my various opinions, how do I know which ones to question? And to be open to being wrong, does that mean I should always assume other people are right and I'm wrong? We can all occasionally be confident yet wrong, but does that mean we should never assert our confidence? And if my confidence level shouldn't be my guide to whether I stick to my guns until I see strong evidence, what should? –  Steve314 Jan 9 '11 at 8:44
show 1 more comment

EDIT: apparently I'm totally wrong, see comments below this answer. Leaving the answer here for educational purposes.

Sadly, you are mistaken. A virtual function may have a definition; a pure virtual function may not. The lack of definition is what makes it pure.

share|improve this answer
7  
Nope, sorry. He's right. –  GManNickG Jan 9 '11 at 7:11
1  
BZZT!!! Wrong! The =0 is what makes it pure. Such functions can have definitions. –  Crazy Eddie Jan 9 '11 at 7:11
4  
huh, colour me surprised. I never knew this. –  Philip Potter Jan 9 '11 at 7:12
3  
Wikipedia explains that "Although pure virtual methods typically have no implementation in the class that declares them, pure virtual methods in C++ are permitted to contain an implementation in their declaring class, providing fallback or default behaviour that a derived class can delegate to if appropriate." So even though it is unusual or atypical for a pure virtual function to define its implementation, it is possible. –  Cody Gray Jan 9 '11 at 7:14
add comment

You know that whatever you answered is right. In my opinion you did a good job by sticking to your answer since you were right. There is no need to lie because if not today some other time interviewer will learn about pure virtual functions!!!!..He might be testing you as well to check how firm are you in your decisions? Are you the person who gets carried away easily?there is no need to loose hope, since you know u r right

share|improve this answer
add comment

Example of a pure virtual function with a definition:

// object.hpp
struct object
{
    // virtual destructor, to allow use as a public base class,
    // but pure to ensure object itself isn't instantiated
    virtual ~object() = 0; 
};

inline object::~object()
{
    // empty implementation
}
share|improve this answer
13  
+1. Excellent use of community wiki! –  Hippo Jan 9 '11 at 7:48
5  
This is not just an example of a pure virtual function with a definition, but an example of how it can actually be useful. +1. –  j_random_hacker Jan 9 '11 at 9:35
3  
Didn't know you could do that. Cool! =D –  gablin Jan 9 '11 at 22:40
1  
This is a way to create a base polymorphic object. You then can use it to dynamic_cast down the hierarchy. Useful in some circumstances, eg plugins, to check that the plugin is of the expected type (with the assumption it definitely will derive from your base class). By the way a pure virtual destructor MUST be given a definition. –  CashCow Jan 30 '11 at 18:23
add comment

The issue at hand is not technical correctness, but social / communication skills. Stand firm, but acknowledge the interviewer's point of view and allow them to save face.

Once you can see what he was fishing for ("pure?" is a good clue), a good answer may be:

It is commonly thought that pure virtual functions cannot have a definition. However, technically speaking, a for the virtual function to be pure, it must have =0 in the declaration. It can still have a definition (try it, it will compile!). Of course, this is rarely used, and in practice when most people say "pure virtual" they imply the definition is absent.

share|improve this answer
3  
You basically copied my comment 25 mins. before I wrote it! How? - +1 and similar-themed comment deleted. –  Steve314 Jan 9 '11 at 9:29
2  
That's another good point. I once argued my grade on a test up because I showed my professor that code I wrote on the test would compile. The compiler doesn't lie... ever... –  jmort253 Jan 9 '11 at 9:42
3  
This was exactly my thought. By just saying "yes it can", without clarification, it seems clear to me that interviewer thought he didn't understand the question. By expanding on the answer, you make it clear that a) you understand the question and b) you actually do know the answer. I don't think the interviewer was necessarily in the wrong for trying to press the point, either, it's clearly a fairly common misunderstanding that people think pure virtual functions cannot have a definition. –  Dean Harding Jan 9 '11 at 10:10
9  
@Steve you get time travel from 500 rep onwards, you must have missed the notification –  Pekka 웃 Jan 9 '11 at 10:26
    
I did the same few years back on a C++ interview (for a high performance system) where I explained that using a function object can have better performance than using a function pointer because of inlining and explained this to him. I also quoted the book "Effective C++". He actually got up to check the book and said he didn't know this and was impressed. It is good to explain your answer. –  Pratik Jan 9 '11 at 23:44
add comment

I've been in interviews where I knew more than my interviewer. However, they wanted someone to fill a role and had no-one (of course) who could interview at that level.

In your case, do you feel it was blind ignorance, or genuine misunderstanding? Perhaps a follow up email with examples and references: see how they react before deciding.

I tend towards the "blind ignorance" though based on your question and would stay well clear...

share|improve this answer
    
Interviewer asked only this question and sent me out. I can't contact them as i have no email id. –  bjskishore123 Jan 9 '11 at 11:08
    
@bjskishore123: via agency? However, I'd stay away if this was it... –  gbn Jan 9 '11 at 11:12
    
yes, via consultancy. –  bjskishore123 Jan 9 '11 at 11:14
    
+1 It is a common experience. I've only once had an interview with anyone who knew enough to check my skill set properly. –  Orbling Jan 9 '11 at 15:12
add comment

I think you should have moved the interview from the desk to a computer with a compiler. That would have solved the issue.

share|improve this answer
add comment

Many times when I interview a candidate, I'm looking to see how the person handles uncertainty, or deals with confrontation. Next time you're interviewing, be sensitive to this, and try to constructively answer the question or explain your position. That may be more important than the correct answer.

share|improve this answer
    
This is a great answer. –  Neil G Jan 10 '11 at 20:40
    
+1: This is how I interview. I care more about how we interact and exchange thoughts more that what's right and what's not. Elaborate your position and/or explain the reasoning behind it and you demonstrate that not only are you competent, but you are a "team player" as well. –  mummey Jan 20 '11 at 2:38
    
Another +1: I think it's important to hire people who can argue well. If a new hire cannot stand up for his or her ideas they won't get far in a team with other strong-willed people! –  Zan Lynx Mar 23 '11 at 21:54
add comment

I totally disagree with idea that you should give up on a company because the guy interviewing you doesn't know the answer to his question. Even when you're working, you're going to meet people who are obstinate even when wrong. It's a good skill to to maneuver people to the right answer.

In my case, the interviewer asked how to calculate the variance of a lot of numbers on many machines. I started by saying that the variance is the mean of the squares minus the square of the means. He interjected, "no, it's E[(x - mu)²]."

I said, "Yes, you're right. But your formula is the same as mine. Let's derive it together." And then we derived it together.

In your situation when you recognize that the interviewer is incredulous, you need to change your approach. Tell him that it's a rarely known feature (this is to make you sound like less of a know-it-all) and if he wants you'll send him an example program or a reference to a C++ book after the interview (this is so that the interview can move gracefully forward.)

Try to imagine things from his perspective. You're going to be interviewing people one day and sometimes you'll be wrong. How would you like a shining candidate to answer such a question?

share|improve this answer
    
The mean is E[(x - mu)²] although you probably meant that. So you can evaluate that to E[ x² - 2xmu + mu² ] = E[x²] - E[2xmu - 2mu²] - E[mu²] E[(x-mu)] is always 0 and E[mu²] = mu² as mu is a constant thus proven. –  CashCow Jan 30 '11 at 18:18
add comment

In a situation like this I would propose to write a simple class with a virtual function with a body and see if it compiles. At the very least, I would propose to google the topic.

If the interviewer takes up the challenge, admits defeat, and does not look like he is about to strangle you after that, then you should be in good shape. Otherwise, this is probably not the person you want to work with.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.