Constexpr : Know Value At Compile Time
int main(int argc, char** argv )
{
int size0;
constexpr auto size1 = 10;
//constexpr auto size2 = size0; //error: constexpr variable 'size2' must be initialized by a constant expression
return 0;
}
Mark Function Delete To Avoid Data Type Conversion
void ShowValue(double value)
{
std::cout << "value: " << value << std::endl;
}
void ShowValue(int value) = delete;
void ShowValue(char value) = delete;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
// ShowValue( 1 ); // compile error
// ShowValue( 'a' ); // compile error
ShowValue( 1.2 );
return a.exec();
}
Left Value Reference And Right Value Reference For Function Parameter
void ShowValue(double &&value)
{
std::cout << "right value reference: " << value << std::endl;
}
void ShowValue(double &value)
{
std::cout << "left value reference: " << value << std::endl;
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
auto value = 1.2;
ShowValue( value );
ShowValue( 1.4 );
return a.exec();
}
/*
left value reference: 1.2
right value reference: 1.4
*/