《c++程序设计语言(第四版)》2.4.3章节
static_assert(A,S) A为常量表达式,当A不为true时,编译不能通过,S会被当做一条编译器错误信息输出。
#define debug qDebug()<<
constexpr int C = 299792458;
void debugValue(int value)
{
const int maxSpeed = 10000000000;
static_assert(maxSpeed < C,"You can't go faster than the speed of light");
debug "value = "<<value;
}
int main(int argc, char *argv[])
{
debugValue(2);
}