[阅读: 230] 2009-02-13 02:26:15
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

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

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