为什么C++被称为语言联盟?

Why C++ is called federation of languages?

我正在阅读有关 C++ 的教程,然后出现以下行。没有提供其他详细信息来进一步解释

C++ is a "federation of languages" and supports multi-paradigm programming, there are many options available to us.

C++被称为语言联邦是什么意思,什么是多范式编程?

这是来自Effective C++ 第三版的解释 55 Specific Ways to Improve Your Programs and Designs 作者:Scott Meyers项目 1:将 C++ 视为语言联盟

Today's C++ is a multiparadigm programming language, one supporting a combination of procedural, object-oriented, functional, generic, and metaprogramming features. This power and flexibility make C++ a tool without equal, but can also cause some confusion. All the "proper usage" rules seem to have exceptions. How are we to make sense of such a language?

The easiest way is to view C++ not as a single language but as a federation of related languages. Within a particular sublanguage, the rules tend to be simple, straightforward, and easy to remember. When you move from one sublanguage to another, however, the rules may change. To make sense of C++, you have to recognize its primary sublanguages. Fortunately, there are only four:

  • C. Way down deep, C++ is still based on C. Blocks, statements, the preprocessor, built-in data types, arrays, pointers, etc., all come from C. In many cases, C++ offers approaches to problems that are superior to their C counterparts (e.g., see Items 2 (alternatives to the preprocessor) and 13 (using objects to manage resources)), but when you find yourself working with the C part of C++, the rules for effective programming reflect C's more limited scope: no templates, no exceptions, no overloading, etc.

  • Object-Oriented C++. This part of C++ is what C with Classes was all about: classes (including constructors and destructors), encapsulation, inheritance, polymorphism, virtual functions (dynamic binding), etc. This is the part of C++ to which the classic rules for object-oriented design most directly apply.

  • Template C++. This is the generic programming part of C++, the one that most programmers have the least experience with. Template considerations pervade C++, and it's not uncommon for rules of good programming to include special template-only clauses (e.g., see Item 46 on facilitating type conversions in calls to template functions). In fact, templates are so powerful, they give rise to a completely new programming paradigm, template metaprogramming (TMP). Item 48 provides an overview of TMP, but unless you're a hard-core template junkie, you need not worry about it. The rules for TMP rarely interact with mainstream C++ programming.

  • The STL. The STL is a template library, of course, but it's a very special template library. Its conventions regarding containers, iterators, algorithms, and function objects mesh beautifully, but templates and libraries can be built around other ideas, too. The STL has particular ways of doing things, and when you're working with the STL, you need to be sure to follow its conventions.

是的,这是来自 Effective C++。作者只是在说 C++ 语法来自一系列子语言。了解它 here

至于多范式编程,它是一种语言支持多种编程风格的能力。这允许不同任务的灵活性。 google 搜索应该会为您解答这个问题。

"Federation of languages" 表示应用 C++ 语言的各种功能和方法的广泛性。

多范式语言组合范式。例如 F-Sharp、OCaml 和 Swift。所以这是一组语言风格。