第三章 深度探索元函数 (1)[22]

[入库:2005年8月19日] [更新:2007年3月24日]

本文简介:选择自 pongba 的 blog

template <class t, class dimensions>

struct quantity

{

    // converting constructor

    template <class otherdimensions>

    quantity(quantity<t,otherdimensions> const& rhs)

      : m_value(rhs.value())

    {

    }

    ...

 

然而,很不幸的是,这样一个通用的转换彻底违背了我们原来的意图,一旦有了这个转换,我们就可以写出下面的代码:

 

//m*a的结果应该是力(force),而非质量(mass)

quantity<float,mass> bogus = m * a;

 

这简直糟透了!

本文关键:第三章 深度探索元函数 (1)
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top