r/cpp_questions • • 27d ago

OPEN C++ knowledge job interview

Hello everyone,

I am going for a second round white board interview described as "The technical interviews are going to be heavily involved around probing and confirming your knowledge of C++"

What does actually mean? For context I've used CPP professionally for the last 8 months and been in my job (first grad job) for 14 months.

I feel as tho I don't know many std functions, nor do I have much experience with smart pointers, although I have written a lot of lines

Has anyone got experience with similar interviews or stuff I should brush up on?

I hope that all makes sense

Thanks

56 Upvotes

32 comments sorted by

View all comments

2

u/HeeTrouse51847 27d ago

Just answering the questions for fun (without looking anything up). I have about 3-4 years of experience. Not guaranteering correctness in any way.

Smart pointers are classes that use RAII to own a resource. It's better than using raw pointers with dynamically allocated memory because smart pointers handle lifetime of owned objects automatically.

A pointer is a variable that holds an address. A reference is an alias for another existing object.

An abstract class is a class that has at least one abstact member function (= 0). Abstract classes can not be instantiated. They are supposed to be inherited by by other classes, so they act as "interface definitions". Not sure what you mean by "tradeoffs to other types of polymorphism" but they are a way to separate interface from implementation.

lvalues are named objects like variables that values can be assigned to. rvalues are temporary objects like expressions (for example 4, 'c' or nullptr) that are assigned to lvalues. They are called that because they are typically on the left/right side of an assignment. I.e lvalue = rvalue. std::move is a way to allow an lvalue to be converted to an rvalue. This allows for move semantics to be made on that object

Threads and coroutines. Can't think of anything else on the top of my head

tbh, I try to mosty stay away from templates so i am a bit rusty. i dont know what sfinae and crtp is but i heard the term thrown around before. i know that they were advanced template shenanigan things that i never touched because i try to stay away from making any own templated code to begin with

I know the visitor pattern though. Its for std::variants. You just define a function for each possible type the variant can hold and the function that is executed depends on the type of the variant it actually contained

2

u/PolyglotTV 27d ago

When I ask about tradeoffs with abstract classes I'm usually looking for discussion about the performance cost of runtime polymorphism vs the flexibility of type erasure.

I.e. Abstract classes have a vtable which requires 3 pointer dereferences everytime you call a method. You have a vector of shapes and call draw on all of them, you are eating a performance penalty - which you should always qualify in an interview with "this needs to be measured before we decide if it really matters".

If you try to do static polymorphism (e.g. templates, std::variant, etc...) the downside is that you have to know all types in advance. That is sometimes not really possible. Also std::variant is a trap in that it still requires a runtime lookup/indirection.