C ++演员

编程入门 行业动态 更新时间:2024-10-10 08:23:37
本文介绍了C ++演员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

一般建议使用 " static_cast< SomeType> someInstance"而不是 传统臭名昭着的(SomeType)someInstance。 我应该对简单类型使用相同的练习, 即代替: 双倍分数=(双倍)n /总数; 我应该写这个吗? double fraction = static_cast< double>(n)/ static_cast< double>(总计); 我找到传统版本更具可读性 在这种情况下。 谢谢!

It is a common recommendation to use "static_cast<SomeType> someInstance" instead of the traditional infamous "(SomeType) someInstance". Should I use the same practice for simple types, i.e. instead of: double fraction = (double) n / total; should I write this? double fraction = static_cast<double>(n) / static_cast<double>(total); I find the traditional version a lot more readable in this case. Thanks!

推荐答案

*雅各布: 使用" static_cast< SomeType>这是一个常见的建议。 someInstance"而不是传统的臭名昭着的(SomeType)someInstance" 我应该对简单类型使用相同的练习,即代替: double fraction =(double)n / total; 我应该写这个吗? double fraction = static_cast< double>(n)/ static_cast< double> ;(总); 在这种情况下,我发现传统版本更具可读性。 It is a common recommendation to use "static_cast<SomeType> someInstance" instead of the traditional infamous "(SomeType) someInstance". Should I use the same practice for simple types, i.e. instead of: double fraction = (double) n / total; should I write this? double fraction = static_cast<double>(n) / static_cast<double>(total); I find the traditional version a lot more readable in this case.

至少有为什么它是一个好主意(TM)使用C ++ 名为强制转换的简单内置类型的三个原因: *它可以帮助你你的代码的维护者记得一般都不要使用C风格的,这有助于防止意外使用。 * C风格的演员可以做const_cast和reinterpret_cast,你可能只需要b $ b不想要(尤其不是指针值)。 *类型定义可能会改变wh代码被维护。 - 答:因为它弄乱了人们通常阅读文本的顺序。 问:为什么这么糟糕? A:热门发布。 问:usenet和电子邮件中最烦人的是什么?

There are at least three reasons why it''s a Good Idea (TM) to use the C++ named casts also for simple built-in types: * It helps you and maintainers of your code remember to not use C-style casts in general, which can help to prevent accidental usage. * C-style casts can do const_cast and reinterpret_cast, which you probably don''t want (especially not for pointer values). * The type definitions may be changed when the code is maintained. -- A: Because it messes up the order in which people normally read text. Q: Why is it such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail?

" Jacob" < JA *** @ yahoo>在消息中写道 新闻:3M ******************** @ telenor ... "Jacob" <ja***@yahoo> wrote in message news:3M********************@telenor... 它是一个常见的建议使用static_cast< SomeType> someInstance"而不是传统的臭名昭着的(SomeType)someInstance" 我应该对简单类型使用相同的练习,即代替: double fraction =(double)n / total; 我应该写这个吗? double fraction = static_cast< double>(n)/ static_cast< double> ;(总); 在这种情况下,我发现传统版本更具可读性。 这是真的!传统版本比C ++ 新的强制转换操作符感觉更自然。 但这就是为什么C ++强制转换操作符看起来如此:它们是如此丑陋 希望劝阻你并警告你不要使用它们。并且您总是可以在文本编辑器中使用查找来获取所有演员阵容。 谢谢! It is a common recommendation to use "static_cast<SomeType> someInstance" instead of the traditional infamous "(SomeType) someInstance". Should I use the same practice for simple types, i.e. instead of: double fraction = (double) n / total; should I write this? double fraction = static_cast<double>(n) / static_cast<double>(total); I find the traditional version a lot more readable in this case. This is TRUE! The traditional version DOES feel a lot natural than the C++ new cast operators. But this is EXACTLY why C++ cast operators look this way: they are so ugly looking to discourage you and alert you from using them. And you can always pick up all casts using a find in a text editor. Thanks!

是等价的 double fraction =(double)n / total; really double fraction = static_cast< double>( n)/总计; 双倍分数=(双倍)n /(双)总数; 不是那么可读 Is the equivilent of double fraction = (double) n / total; really double fraction = static_cast<double>(n) / total; double fraction = (double) n / (double) total; isn''t that readable either

更多推荐

C ++演员

本文发布于:2023-11-25 11:56:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1629647.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:演员

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!