C++0x OOP 范式转变?

发布于 2024-10-15 06:52:36 字数 18 浏览 2 评论 0原文

有吗?如果有,是哪些?

Are there any and if yes, which ones?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

相对绾红妆 2024-10-22 06:52:36

你所说的“范式转变”是什么意思?

C++0x 引入了许多新功能,这些功能当然会改变您编写程序的方式。

有些小事情可能会对所使用的语法产生很大影响,但不会对语义产生太大影响。例如 lambda 函数和基于范围的 for 循环:它们将为我们已经在做的事情提供更好的语法。

然后还有一些重大事情将改变事物的运作方式。特别是:

  • 右值引用可以让您以不同的方式思考对象如何工作以及如何使用它们:按值传递(和返回)对象可能会更容易。

  • 显式转换运算符将允许我们定义转换运算符,而在 C++03 中这样做是有风险的。

What do you mean by "paradigm shift"?

C++0x introduces many new features that will of course change the way you write programs.

There are little things that will probably have a big impact on the syntax used, but which won't change the semantics that much. Examples are lambda functions and range-based for-loop: they'll provide a better syntax for what we all are already doing.

Then there are big things that will change the way things work. In particular:

  • Rvalue reference could make you think in a different way about how objects work and how to use them: it'll probably be easier to pass (and return) objects by value.

  • Explicit conversion operators will let us define conversion operators, while doing this in C++03 was risky.

紧拥背影 2024-10-22 06:52:36

C++0x 没有引入任何新的范式,也没有改变任何范式。

编辑:然而,这些范例的实现首先会受到可变参数模板和右值引用的一些相当大的变化的影响。

C++0x does not introduce any new paradigms and doesn't change any paradigms.

Edit: The implementation of those paradigms, however, is subject to some pretty big change with variadic templates and rvalue references, just to begin with.

删除→记忆 2024-10-22 06:52:36

事实上,我认为是的,存在范式转变。警告:我从未用 C++ 编写过面向对象的代码。

可能允许范式转变的变化是智能指针 std::shared_ptr 的标准化。现在标准库终于包含了一个实现良好、高效且可能没有错误的共享指针。

C++ 专家知道让它们正确是多么困难,并且大多数引用计数指针的库实现可能都包含微妙的错误。因此,即使(由于某种脑死亡的原因)公司禁止使用 Boost,最终拥有一个可靠的实现也很重要。

可能对内存泄漏的数量产生巨大的影响:如果面向对象的C++应用程序停止泄漏内存,将是一个范式转变。

另一方面,在 OOP 代码中使用自己的智能指针的公司在未来十年内可能不会转向 C++0x。

(再次强调这一点,因为它被反复误解:我并不是将智能指针技术称为范式转变。我指的是面向对象中内存泄漏的完全消失架构。)

As a matter of fact, I think that yes, there is a paradigm shift. Caveat: I have never written object-oriented code in C++.

The change that may allow a paradigm shift is the standardization of the smart-pointer std::shared_ptr. Now finally does the standard library contain a well implemented, efficient and probably bug-free shared pointer.

C++ experts know how hard it is to get them right, and that most library implementations of reference-counting pointers probably contain subtle bugs. It’s therefore important to finally have a reliable implementation even if (for some brain-dead reason) the company forbids the use of Boost.

This might have drastic consequences on the number of memory leaks: If object oriented C++ applications stopped leaking memory, that would be a paradigm shift.

On the other hand, companies that use their own smart pointers in OOP code will probably not switch to C++0x in the next ten years anyway.

(Just to emphasize this once more, since it’s been repeatedly misunderstood: I am not referring to the technology of smart pointers as a paradigm shift. I am referring to the complete disappearance of memory leaks in object-oriented architectures.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文