Interview Questions

Tech-Archive recommends: Fix windows errors by optimizing your registry



Do you guys remember the "MFC interview questions" post a few weeks ago?

Well, I'm trying to hire a Jr. programmer to do some C#/Silverlight work and
also help out with the C++/MFC stuff. Therefore OOP understanding is the
most important part for me. (The rest can be taught)



What do you guys think of these questions? Can you think of some good
questions to judge a persons problem solving skills?



1. What is polymorphism?

2. What is a virtual function, and how is it used?

3. What is a pure virtual function, and why would you use it?

4. When and why would you want to have a virtual destructor?

5. What is the difference between a pointer and a reference? (In
other words: What must you always do to a reference?)

6. What's wrong with the following code sample?

class Sub

{

};



class Super1: public Sub

{

};



class Super2 : public Sub

{

};



class DoesSomething

{

public:

void DoSomething(Super1 *pSuper)

{

}



void DoSomething(Super2 *pSuper)

{

}

};



void main()

{

std::vector<Sub *> SubVector;

SubVector.push_back(new Super1);

SubVector.push_back(new Super2);

std::vector<Sub *>::iterator cur = SubVector.begin();

DoesSomething Something;

while (cur != SubVector.end())

{

Something.DoSomething(*cur);

delete *cur;

}



}

How would you solve this problem?



Thanks

AliR.






.



Relevant Pages

  • Re: Interview Questions
    ... understanding of design patterns (atleast they should have heard of the ... What is a pure virtual function, and why would you use it? ... class Super1: public Sub ... void DoSomething ...
    (microsoft.public.vc.mfc)
  • Re: memory usage of Virtual function poiters
    ... >void foo ... have an extra hidden data pointer (the pointer to the virtual function ... member which begs the question as to why you had 20 originally. ... but also how could this design meet the same needs as the previous ...
    (alt.comp.lang.learn.c-cpp)
  • Re: memory usage of Virtual function poiters
    ... > void foo ... The pointer points to table of pointers, ... address of the function to call for each defined virtual function. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Hmm... inheritence... hmmm
    ... is a class Dog or any derived from it. ... would work without throwing a bad_cast exception. ... types are compatible, then calls the virtual function of the class, which ... void mate{ ...
    (comp.lang.cpp)
  • Re: Sorting a CList
    ... You are correct about the virtual function requirement. ... use dynamic_cast on a pointer to pointer of type X**, ... cannot cast from void*, so when you start from void*, as the sort ... will have this initial unchecked cast at the very least, ...
    (microsoft.public.vc.mfc)