《C++ templates》的Expression Templates一问

boodweb 2006-02-04 11:19:10
18.2中说Scalar必须用值传递,我怎么也搞不懂原因
有没有看明白的解释一下?

谢谢!
...全文
172 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
healer_kx 2006-02-07
  • 打赏
  • 举报
回复
其实只要能够生成计算表达式就可以了。关键在于那个double类型的萃取,是不是引用都是无所谓的。
healer_kx 2006-02-07
  • 打赏
  • 举报
回复
Sorry,我才看到你说得那个问题了。。。看来我真的是理解错了。
它的意思可能是说Scalar对象是在编译过程中产生的函数operaor * 的那个
return的A_Scalar<T>(s);它是一个临时对象。
用白话说,你是引用不住它的,(它在构造后就会失效)

我还得再理解一下。。。 。。。还有些问题没有想通呢。
healer_kx 2006-02-07
  • 打赏
  • 举报
回复
我把那一章的代码都敲了一遍。。。我这里是可以的。
要么是我没有理解你的意思。。。
我的MSN个人空间是http://spaces.msn.com/healerkx
上面的代码你可以在VC7上运行下。
顺便我们再讨论一下。

healer_kx 2006-02-07
  • 打赏
  • 举报
回复
我再看看,我怎么不觉得啊。看完了再答复您。
boodweb 2006-02-07
  • 打赏
  • 举报
回复
可是书上明明特别指出说会有问题啊……
boodweb 2006-02-06
  • 打赏
  • 举报
回复
楼上地可以详细解释一下么?
为什么书上那么实现就一定要值传递?
healer_kx 2006-02-06
  • 打赏
  • 举报
回复
可以,谁说一定是数了,当然了,这也需要你改变operator*的声明和实现了。
wshcdr 2006-02-06
  • 打赏
  • 举报
回复
UP
Discovering Modern C++: An Intensive Course for Scientists, Engineers, and Programmers (C++ In-Depth Series) By 作者: Peter Gottschling ISBN-10 书号: 0134383583 ISBN-13 书号: 9780134383583 Edition 版本: 1 出版日期: 2015-12-27 pages 页数: 480 内容简介: As scientific and engineering projects grow larger and more complex, it is increasingly likely that those projects will be written in C++. With embedded hardware growing more powerful, much of its software is moving to C++, too. Mastering C++ gives you strong skills for programming at nearly every level, from “close to the hardware” to the highest-level abstractions. In short, C++ is a language that scientific and technical practitioners need to know. Peter Gottschling’s Discovering Modern C++ is an intensive introduction that guides you smoothly to sophisticated approaches based on advanced features. Gottschling introduces key concepts using examples from many technical problem domains, drawing on his extensive experience training professionals and teaching C++ to students of physics, math, and engineering. This book is designed to help you get started rapidly and then master increasingly robust features, from lambdas to expression templates. You’ll also learn how to take advantage of the powerful libraries available to C++ programmers: both the Standard Template Library (STL) and scientific libraries for arithmetic, linear algebra, differential equations, and graphs. Throughout, Gottschling demonstrates how to write clear and expressive software using object orientation, generics, metaprogramming, and procedural techniques. By the time you’re finished, you’ll have mastered all the abstractions you need to write C++ programs with exceptional quality and performance.

65,208

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧