You have several flaws in your code:
- You have declared a reference parameter for a fundamental type instead of a value parameter (you do not intend to modify it - so, why a reference parameter?).
- You pass an rvalue to an lvalue reference (a literal to a reference) - this is not allowed.
- You have a float instead of the double parameter (a floating-point literal is of type double unless you add a float suffix (e.g. 1.0F)).
- You pass an int to a float (assuming you replace the float reference by a plain float) - this is not an error, but you add complexity without cause.
How about
void pauseScreen(double duration_in_sec) {
if ( duration_in_sec == 0.5 ) {
std::this_thread::sleep_for(0.5s);
} else if ( duration_in_sec == 1.0 ) {
std::this_thread::sleep_for(1s);
} else if ( duration_in_sec == 2.0 ) {
std::this_thread::sleep_for(2s);
} else {
std::this_thread::sleep_for(4s);
}
}
int main(){
std::cout<<"Hello";
pauseScreen(1.0);
return 0;
}
Cheers
Andi