+ 1

Why constexpr is not working for const data member

Hi Refer code below: Trying ro create a functor and constructor as constexpr Whats wrong in this ? Does "const variable !=0" a const expression ? https://code.sololearn.com/cshO4CMzMYk0/?ref=app

30th Nov 2022, 3:38 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
3 Respuestas
0
No, deno is a const value in the ctor context but it can be any value. Futhermore static_assert is for compile-time assertions then the condition has to be compile-time avaible expression . Think it like a preprocessor macro
30th Nov 2022, 11:31 PM
KrOW
KrOW - avatar
0
It seems static_assert is for template only... at max, it works for local scoped variable , but not for argument. even const ref argument is also not working void check(const int& b) { const int a = 3; static_assert(a!=0,"not zero"); } a will work on static assert , but b woll not
1st Dec 2022, 5:27 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
I belive , void check(const int& b) { const int a = 3; static_assert(b!=0,"not zero"); }c above should work if check is called with either 1.rvalue check(5); Or 2.Const int const int a = 7; check(a);
1st Dec 2022, 5:29 PM
Ketan Lalcheta
Ketan Lalcheta - avatar