1.断言(assert)
#include<iostream> #include<cassert> using namespace std; //区别用指针的大小 int divv(int a, int b) { assert(b != 0); //断言 return a / b; } int main1() { cout << divv(1, 0) << endl; cin.get(); }
2.静态断言(static_assert)
static_assert(sizeof(void*) == 8, "is not 64, baby"); int main() { // int b = 0; const int a = 0; //static_assert(a > 0, "is not 64, baby"); //变量不可以使用static_assert cin.get(); }