I m宣读了Bjarne Stroustrup的书,“C++方案编制语言”,我发现了一个解释static_assert
的例子。 我的理解是,static_assert
只适用于能够用经常表述的方式表述的内容。 换言之,它绝不能包括意图在时间评估的表述。
The following example was used in the book (I does some change in the Code). 但我认为,这不应改变本书所列原始范例法典所产生的任何东西。
#include <iostream>
using namespace std;
void f (double speed)
{
constexpr double C = 299792.468;
const double local_max = 160.0/(60*60);
static_assert(local_max<C,"can t go that fast");
}
int main()
{
f(3.25);
cout << "Reached here!";
return 0;
}
以上是汇编错误。 http://ideone.com/C97oF5“rel=”http://ideone.com/C97oF5。
The exact code from the book example:
constexpr double C = 299792.458;
void f(double speed)
{
const double local_max = 160.0/(60∗60);
static_assert(speed<C,"can t go that fast"); // yes this is error
static_assert(local_max<C,"can t go that fast");
}