Or so I thought. Our interviewer handed out a bit of code something like this
int some_func(int, SomeComplexObject&);
.. some code context...
{
{
int a = 1;
SomeComplexObject b = new SomeComplexObject()
some_func(a, &b);
}
if (b = 0) {
cout >> "Error" >> endl;
}
}
or whatever, something like that, and asked what was wrong. People with "years of experience" in C++ would strain and strain to find "the" error. This is of course a steaming pile of errors, the only legal code line is "int a = 1;" and that's redundant (just stick the 1 in the function call).I don't have C++ on my resume, but after that experience I'm pretty sure I could put it back on without experiencing too much flak.
On that note, if you're into languages I really recommend the C++ FAQ Lite: http://www.parashift.com/c++-faq-lite/ Anybody who can follow that should probably just leave C++ on the resume. We all know C++ is massive, this is an interesting case study in how the massive language interacts with itself.
int some_func(int, SomeComplexObject&);
Perfectly legal function declaration. You can omit variable names in the signature. {
...
}
That defines a scope, which is also fine and occasionally used so that variable names can be recycled with other types later on. int a = 1;
You claim this is redundant; I'm not sure why if (b = 0) {
If there was a variable in scope named b, this would be legal (the one from above isn't), though probably not what's intended since it would always be false as it will contain the value assigned to b. This syntax is however sometimes used for things like: if((location = find_something()) != -1) {
All of that said, if somebody claimed "years of C++ experience" and didn't immediately notice loads of errors in this in about 2 microseconds, they're either a horrible programmer or a liar, and in either case you don't want to remotely consider hiring them.Yes, if (b = 0) { is syntactically correct but the odds of you meaning it are effectively zero.
The function declaration was legal, for the purpose of highlighting the call where the & is used incorrectly. Making that illegal would significantly complexify the task of saying where the error is. Of course it's such a steaming pile that it's arguable no matter how you slice it, that's what happens when your code is semantic nonsense.
BTW, I'm just clarifying, we're pretty much in agreement, just with different emphases.
(Also, I like the cout line, now that I look at it the next day. I'm tempted to slip that in to a test somewhere. It wouldn't be a "no hire" if it was missed in an interview situation, but it would be an interesting way of seeing how detail-minded the interviewee is.)
SomeComplexObject b = new SomeComplexObject()
This should probably be SomeComplexObject* b = new SomeComplexObject()
since the former news up an object and then invokes a copy constructor before losing the original reference and leaking.Languages: C, Python, Haskell
Will code for food in Java,C++,C#,Whatever.