static_assert( 布尔常量表达式 , 不求值字符串 ) (1) static_assert( 布尔常量表达式 ) (2) (C++17 起) static_assert( 布尔常量表达式 , 常量表达式 ) (3) (C++26 起) 声明静态断言。如果断言失败,那么程序非良构,并且可能会生成诊断错误信息。
structX{staticconstintn=1;staticconstexprintm=4;};constint*p=&X::n,*q=&X::m;// 因为X::n 与 X::m 被 ODR 式使用constintX::n;// ……所以需要定义constexprintX::m;// ……(但 C++17 中的 X::m 不需要) 关键词 static
This convenience macro expands to the keyword_Static_assert. Example Run this code #include <assert.h>intmain(void){static_assert(2+2==4,"2+2 isn't 4");// well-formedstatic_assert(sizeof(int)<sizeof(char),// compile-time error"this program requires that int is less than char");...
structX{staticvoidf();// declarationstaticintn;// declaration};X g(){returnX();}// some function returning Xvoidf(){X::f();// X::f is a qualified name of static member functiong().f();// g().f is member access expression referring to a static member function}intX::n=7;...
T1,T2);static_assert(std::is_same_v<decltype((bar<char>)(0,0)),int>);static_assert(std:...
break; cout << x << endl; x++; } break语句只能跳出本层循环,假如你要跳出一个三重嵌套的循环,你就要使用包含其它的逻辑或者用一个goto语句跳出这个嵌套循环. case 在switch里面用来检测匹配 . default,switch catch catch 语句通常通过throw语句捕获一个异常. ...
intmain() {union{inta;constchar*p; }; a=1; p="Jennifer"; } union-like class #include<iostream>//S has one non-static data member (tag), three enumerator members,//and three variant members (c, n, d)structS {enum{CHAR, INT, DOUBLE} tag;union{charc;intn;doubled; ...
a cast expression to rvalue reference to function type, such as static_cast<void (&&)(int)>(x). (C++ 11 右值强转函数类型) Properties: Same as glvalue (below). Address of an lvalue may be taken: &++i[1] and &std::endl are valid expressions. ...
int x = static_cast<int>(President::MCKINLEY); // can specify any integer data type as the underlying type enum class Day : char {MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY}; 6. Templates 6.1. Function Templates template <class T> void swap(T &i, T &j) { T temp = i; i = ...
static thread_local (C++11 起) extern mutable 声明说明符序列 中只能出现一个存储类说明符,但thread_local可以与static或extern一起出现(C++11 起)。 mutable不会影响存储期。它的用法参考const/volatile。 其他存储类说明符可以在以下声明的声明说明符序列 中出现: ...