static assert
It is a new feature in c++11, it does the check of specific condition at compile time. We always prefer compile time error than run time error.
source code with example:
/* Program: Static Assert Author: Alpha Master Date: 14 March 2021 */ //Header File #include<iostream> const int max_speed = 120; int main() { std::cout<<"Static Assert"<<std::endl; //const int speed = 190; //error: static assertion failed: You have crossed the Max speed const int speed = 90; //static assert takes (!condition, message) static_assert(speed<max_speed, "You have crossed the Max speed"); std::cout<<"Speed:"<<speed<<std::endl; return 0; }
Output:
Static Assert Speed:90