views:

447

answers:

10

I've got about 2/3 years C++ experience but I've spent most of my career doing Java. I'm about to go for an interview for a C++ programming role and I've been thinking about the best way to brush up my C++ to make sure I don't get caught out by any awkward questions. What would you recommend?

+9  A: 

Effective C++ by Scott Meyers

Thorsten79
Just got around to doing this, what a great book.
Benj
Just as a bit of feedback to this question, I did get the job and this book was invaluable! I learned a number of things from it which I didn't know before and several of them came up in the interview. Thankyou for the recommendation! I've read the whole thing now and feel I know alot more about C++ as a result.
Benj
+3  A: 
  • Go through the questions on SO with C++, OOP tags.
  • C++ FAQ
codaddict
+1 for the FAQ, if it trapped people in the past, it is likely that it will be use to trap them in intervention if such is the goal :)
Matthieu M.
+4  A: 

If you have enough time try to write an application using C++ - go over the basics so when you'll be asked to show coding skills you'll be able to write code fluently.

I've noticed that during C++ centric interviews it is common practice to ask question about how it works:

  • How virtual methods are implemented?
  • What happens when you call new - how memory is allocated?
  • What is the difference between struct and class?
  • Why should you mark your class d'tor as virtual?

I guess a good way to learn all those is to read a good C++ book - if you have the stomach for it you can read Stroustrup book - but there bound to be other books just as good (with less pages in them).

Have a look at the C++ Style and Technique FAQ

Dror Helper
A bad way is to read `Stroustrup`, it's way too comprehensive I am afraid and I would only recommend it (paradoxally) to someone who has already a strong graps of what C++ is. Perhaps that I was daunted by the emphasis on syntax...
Matthieu M.
You're right - instead read his FAQ - it has a good explanation of C++ and howtos
Dror Helper
David Thornley
There's lots of really good answers here but I think I'm going to accept this one because it seems the most useful to me. The C++ Style and Technique FAQ has been (and is continuing to be) a very good read.
Benj
A: 

It depends: I went for a job with a certain large games company and 90% of the questions were graphics and micro-optimisation questions (this was for a C# testing role, stupidest test of my life!).

However, if you're going for a normal desktop-app role, you'll probably get asked about UIs, or if you're going for some sort of embedded computing role you'll likely be asked about optimisation and memory management.

In any case, I'd brush up on your BOOST, as an example of a good library, and your pointer knowledge.

Ed Woodcock
+5  A: 

As an interviewee, I depend on experience. As an interviewer, my favourite (and often only) C++ interview question is "Tell me about the copy constructor". It's amazing how many avenues this opens up, and how few people are aware of them - it can make for a very short interview. If the interviewee gets past that, I then ask "Which are your favourite C++ books, and why?"

anon
Wow.. I would never have guessed that. I'm stil a student, but I remember learning about copy constructors basically right away when we first learned about object-oriented programming. Do people just forget, or are there that many unqualified C++ programmers floating around out there? I know all too well how many bad PHP programmers there are out there.
Andrew Noyes
@Andrew: I assume that's why he didn't phrase it as "What is a copy constructor", but "tell me about". That might lead to a lot of other questions on top of the obvious "what does it look like". I assume Neil just uses it as a starting point, rather than a simple "do you know what a copy constructor is? Yes/no" kind of question.But yes, there are many unqualified programmings floating around in every language, and C++ definitely has its fair share of them.
jalf
@jalf Correct - it's just a starting point. I don't really care what they tell me so long as its correct and so long as they can talk at length.
anon
@andrew You'd be surprised. I've lost count of the number of interviews I've terminated because the interviewee just gawped at me when I asked the question. Mind you, I haven't done any interviewing for quite a bit, so maybe things have improved, though I doubt it somehow.
anon
@Neil: On our job Effective C++ is a required reading. My colleague who regularly interviews tells me that there are many applicants who don't know the basics of C++ like why a destructor should be made virtual. We don't ask for funky alexandrescuish language features though.
Thorsten79
+4  A: 

Study the 88 GoTW entries.

Manuel
+5  A: 

Know the language. You can try to predict what questions they'll ask, but C++ can mean a lot of different things depending on who you ask. To some people, it's a clumsier Java, and all the questions will be about dynamic memory allocation, virtual functions and inheritance. To others, it's all about RAII, and avoiding memory management.

Some think the STL is the most important to ask questions about and some might want to dig in to your knowledge of some of the subtler aspects of the language (ranging from the copy constructor that Neil mentioned in his answer, to common cases of undefined behavior, or exception safety)

It's a big, complex language, and people can ask a lot of different questions about it. Unless you have some idea what areas they're likely to focus on, you're not likely to achieve much with last-minute brushing up.

jalf
Indeed. "C++" could mean: "Yay we love templates and use them everywhere, so be ready to have your brain turned to mush" BUT it could mean "We do C-with-classes style C++ and ignore half the features of the language"
RyanWilcox
A: 

I would just review the basics of the language: make sure you remember how to make classes, know when to pass it via reference and when to pass in via pointer, and why you'd want to do that vs pass by value. Why you'd want a virtual method, and what are the reasons one uses the C++ style casts vs the C style casts, when you'll need a copy constructor, things like that

I'd imagine what would help is remembering a war story or two about C++: ("man, const correctness is hard!", "so I once got into a fight with a coworker/teacher about this finer point of C++, and I learned that.."

If the job is for an entry level C++ job (which it should be with your limited C++ experience), I'd imagine that would be fine and that you'll (hopefully) not get cast too deep without a paddle/senior engineer to guide you.

RyanWilcox
A: 

"write a function that counts the number of 'on' bits in a byte"

that never gets old...

I saw a cool bitwise way of doing it once that could count all the on bits in a 32 bit DWORD in like 4 or 5 operations!

If I were an interviewer in this day and age I'd ask "what do you know about lock free codeing?"

matt