当前位置:网站首页>55 specific ways to improve program design (1)

55 specific ways to improve program design (1)

2022-06-25 15:04:00 I know everything

Get used to C++

Clause 01: Depending on the C++ For a language Federation

  •  C. At the end of the day C++ Still with C Based on . block (blocks)、 sentence (statements)、 The preprocessor (preprocessor)、 Built in data types (build-in data type)、 Array (arrays)、 The pointer (pointers) All from C. A lot of time C++ The solution to the problem is actually just a higher level C solution ( For example, clause 2 Talking about an alternative to the preprocessor , Clause 13 When it comes to managing resources with objects ), But when you take C++ Internal C When ingredients work , Efficient programming rules reflect C Language limitations : No template (templates)、 No abnormal (exceptions)、 No overloading (overloading) etc. ...
  • Object-Oriented C++. This part is C with Classes Appeal :classes( Including constructors and destructors ), encapsulation (encapsulation)、 Inherit (inheritance)、 polymorphic (polymorphism)、virtual function ( Dynamic binding )...... wait . This part is the classical code of object-oriented design C++ Most direct implementation .
  • Template C++. This is a C++ Generic programming for (generic programming) part , It is also the least experienced part of most programmers .template Relevant considerations and design have pervaded the whole C++, Good programming practices “ only template apply ” Special provisions are not uncommon ( For example, clause 46 When it comes to calling template function How to assist in type conversion ). In fact, because of template Powerful , They bring new paradigms (programming paradigm), It's called template metaprogramming(TMP, Template metaprogramming ). Clause 48 This provides an overview , But unless you are template The backbone of the radical team , There is no need to worry about this .TMP The relevant rules are rarely related to C++ Mainstream programming interacts .
  • STL.STL It's a template library , Look at the name , But it's a very special one . It's for containers (containers)、 iterator (iterators)、 Algorithm (algorithms) And function objects (function objects) There is excellent coordination and coordination between the two protocols , However templates And libraries can also be built with other ideas .STL Have their own special way of doing things , When you are with STL Working together , You must abide by his rules .

        C++ It's not an all-in-one language with a set of rules : He is a federal government composed of four sub languages , Each sub language has its own rules . Remember these four sub languages , You'll find out C++ Easy to understand a lot .

please remember

  • C++ Efficient programming rules vary depending on the situation , It's up to you to use C++ Which part of .

原网站

版权声明
本文为[I know everything]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202200513130078.html