It was funny for me, and I'm interesting the reaction for this question of the community. It was interview for C++/Qt developer, and question was asked "What is virtual function". Not something like "how polymorphism in C++ works" or "how virtual functions works" but what is. My first thought was to answer "Virtual functions(methods) are methods that have word "virtual" before it's signature", but I explained about how they works =) What do you think, is this a proper formed question? And what will you ask for that question?

PS: I hope that this part of stackexchange are proper for this question

  • 1
    It's a perfectly proper question, and one I've used on phone screens as a weed out question. I've used it because a disturbing fraction of candidates could not give the answer you did. – Gort the Robot Sep 8 '13 at 3:58

Maybe if you're a non-native English speaker you'd get some amusement out of this, but it's a valid question. The interview is a test of both knowledge and communication skill - and communication doesn't only mean your ability to explain concepts, but also your ability to understand what they are asking.

The question could also be asked 'What does the virtual keyword do' or 'What is the purpose of a virtual function'; without knowing the precise answer that they are looking for it's hard to know how they should word their question for least ambiguity.

I think that questions like this can be expressed in a very open ended way ('Tell me about virtual functions') which leaves you to explain the most important concepts and demonstrate your knowledge.

|improve this answer|||||
  • Excellent answer. After the OP answers a question he can ask if he has supplied all the information needed or whether he should elaborate. – dcaswell Sep 7 '13 at 23:46

I think it is a perfectly valid question. I'll quote wikipedia as they state it better than me:

In object-oriented programming, a virtual function or virtual method is a function or method whose behavior can be overridden within an inheriting class by a function with the same signature. This concept is a very important part of the polymorphism portion of object-oriented programming (OOP).


|improve this answer|||||
  • 2
    According to the wikipedia definition, any "normal" method in C++ is virtual regardless of this keyword, since they "can be overridden within an inheriting class by a function with the same signature" – Thiago Silva Sep 7 '13 at 22:01
  • 4
    @ThiagoSilva Not really true. If a subclass has a method with the same name as a parent class, and the parent class is not virtual, then it hides the method rather than overriding it. This is important because the behavior of accessing the method through a pointer to the parent class will act differently. If a subclass overrides a parent class method, you will get the subclass version through the parent pointer. If it hides it, you will get the parent version. – Gort the Robot Sep 8 '13 at 3:57
  • Of course it's not quite so: virtual or not, you still retain access to all accessible methods. You simply explicitly which one you want: A::method or B::method. Otherwise there'd be no way to call the base class's method in a derived one :) – Reinstate Monica Sep 8 '13 at 7:49
  • @StevenBurnap I guess we disagree on the use of the term "overrides" – Thiago Silva Sep 8 '13 at 21:12
  • @ThiagoSilva - I would call what you are doing an "error", not "overriding". It is an illegal error in my world. Code that doesn't compile clean with a boatload of warnings options enabled needs a project waiver. Overriding a non-virtual function gets a compiler warning for hiding the parent class method, and that warning is not going to get a waiver any time soon. – David Hammen Sep 9 '13 at 10:26

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