What are major concepts every C++ programmer should know about the language?

Mudassir Ali
Feb 10, 2020 06:02 AM 0 Answers
Member Since Dec 2019
Subscribed Subscribe Not subscribe
Mudassir Ali
- Feb 10, 2020 06:03 AM

It is true that C++ is built on top of C, the compatibility being 90+%. Therefore there is a very strong tendency to write C-style code with C++. Avoid this. That’s the first thing to keep in mind. Following are a list of techniques / features / terms you should understand and use regularly in your C++ code to reap the benefits of the language.

1. Various uses of the ‘const’ keyword and its liberal use.
2. C++ references, const references and temporaries.
3. Basic class syntax, difference between public, protected and private inheritance and *virtual functions*.
4. How the constructor and destructor work, their relation to definition scope for C++ objects on stack, and to the new and delete operators for C++ objects on the heap. The importance of virtual destructors.
5. Default initialization vs value initialization.
6. Copy constructor, assignment operator, nothrow swap.
7. Understand and adopt Resource Acquisition is Initialization (RAII).
8. Operator overloading – especially chaining of overloaded operator calls.
9. What “new operator” and “delete operator” do, and their distinction from “operator new” and “operator delete”. Also the different variants of new and delete, including placement new.
10. Exceptions, how to use them efficiently and unobtrusively.

STL + More advanced stuff

11. Rules for overload resolution and what leads to hiding of functions / data in a class or its base classes.
12. Get a basic hang of templates and terminology surrounding them: class template vs template class, template id, template parameter vs template argument, function template. Understand template specialization and partial template specialization. Understand overload resolution between non-template and template functions.
13. Advanced class design techniques – Pimpl idiom, proxies (e.g. smart pointers), private inheritance and template method pattern. Rule of Three, Rule of Zero.
14. STL: different classes of objects – containers, iterators, algorithms, functors, container adaptors, iterator adaptors, functor adaptors.
15. STL dos and don’ts. Understand how to perform specific operations on specific containers e.g. deleting elements from sequence containers vs associative containers.
16. Basic understanding of the iostream facility: the class hierarchy, role of streams and streambuffer classes, manipulators.
17. Namespace, argument dependent lookup (Koenig lookup), its implications.
18. Copy elision and return value optimization.

C++ 11 stuff
19. auto: use the auto keyword in its new avatar liberally to spare yourself from having to type ugly, convoluted, nested typenames.
20. rvalue references, move constructors, perfect forwarding, move iterators: I wouldn’t be overstating things if I said, you’d be halfway through C++ 11 by getting a grip on just this one topic. There is an immense amount of subtlety in this topic – and enough reason to hate C++ for it. And yet this is the one facility that drives a lot of the other new features, especially in the STL containers and generally in allowing for more efficient semantics in class interfaces.
21. initializer lists: very useful stuff.
22. range based for-loops: lets you write neat loops around containers.
23. lambda functions: very useful if you know when to deploy and how to format lambdas right. Can become unreadable junk if you don’t.
24. STL containers: forward_list (singly linked list), unordered_set (hash table)/unordered_map (hash based symbol table), emplace / emplace_back methods in sequence containers, move_iterators.
25. Ratio and Chrono libraries.
26. Concurrency and atomics: big topic. Worth getting familiar with how you could port your existing Win32 or pthreads code to C++ 11. But there is much more to this library – including atomic data types and operations, futures and promises.

Really useful Boost libraries
Boost Any
Boost Variant
Boost Exception
Boost Regex
Boost Range
Boost Bimap
Boost DateTime
Boost Filesystem
Boost Thread
Boost Coroutine
Boost Asio

Boost Phoenix
Boost MPL
Boost Spirit
Boost Fusion
Boost Xpressive

Reply on This
Replying as Submit
0 Subscribers
Submit Answer
Please login to submit answer.
0 Answers