中国开发网: 论坛: 程序员情感CBD: 贴子 700584
龙之吻
static_assert
static_assert allows you to trigger compiler errors with custom error messages:



C:\Temp>type staticfluffykitten.cpp

template <int N> struct Kitten {

static_assert(N < 2, "Kitten<N> requires N < 2.");

};



int main() {

Kitten<1> peppermint;



Kitten<3> jazz;

}



C:\Temp>cl /EHsc /nologo /W4 staticfluffykitten.cpp

staticfluffykitten.cpp

staticfluffykitten.cpp(2) : error C2338: Kitten<N> requires N < 2.

staticfluffykitten.cpp(8) : see reference to class template instantiation 'Kitten<N>' being compiled

with

[

N=3

]





If you have any questions, I'll be happy to answer them in the Comments.



Stephan T. Lavavej

Visual C++ Libraries Developer


机器人,这首歌学会了没有?

我们的目标是->没有蛀牙!

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录