C++ features to learn [closed]
C++ has too many features, and I can't see how any programmer is able to remember all these features while programming. (We can see how this affected the design of newer languages, such as Java)
So, what I need is a list of features that are enough to know, disregarding all the others, to create c++ programs, perhaps created by someone who thought the same way as I did.
Hope I was clear en开发者_如何学Cough.
Learn Resource Acquisition Is Initialization.
The technique was invented by Bjarne Stroustrup, to deal with resource deallocation in C++.
[...]
RAII is vital in writing exception-safe C++ code: to release resources before permitting exceptions to propagate (in order to avoid resource leaks) one can write appropriate destructors once rather than dispersing and duplicating cleanup logic between exception handling blocks that may or may not be executed.
C++ is an object-oriented language with features like inheritance, encapsulation and polymorphism that is also found in popular languages like Java, C# etc. C++ also features generics via templates. However, in C++ you have to explicitely handle memory deallocation (ie. no garbage collection). This makes it very important to be able to release resources and deallocate memory in a controlled manner, and that is why I believe RAII is a very fundamental concept in C++. You will have a hard time understanding a "smart pointer" unless you understand RAII.
This is really an impossible to create list. Every place I work has a different acceptable subset of C++. So its going to be different depending on what you're developing on. I've seen C++ that truly is just C with occasional use of the "class keyword" to very run-time polymorphism oriented code to template meta-programming heavy code. Then the practices are going to change based on what frameworks/libraries/platforms you are targeting.
The best I could suggest is reading various coding standards and seeing the how they suggest you ought to write code using C++.
- Google's Coding Standard
- Sutter's Coding Standard Book
You learn and remember them by having a need for them. I'm not sure what sort of "features" you're looking for. "virtual functions" are definitely something you want to learn, but I don't really know your background. Should I be suggesting polymorphism/class inheritance too? Template classes/functions?
I think templates are such a feature...
Do you have a tool box containing too many tools? Then don't use them all? Use the ones you need.
Read a good book with C++ best practices and design patterns.
Don't be in too much of a rush to master a language. Peter Norvig (of Google) argues that it takes about 10 years to gain a mastery at anything.
精彩评论