I have a code that returns true in one line, false in the other.
For example,
struct Z{
static const int value = 10;
};
struct A : Z{
};
struct B : Z{
};
int main(){
if(std::is_same<A,B>::value){
static_assert(std::is_same<A,B>::value , "why am i here?");
}
return 0;
}
Can someone please explain why it throws a static assert error?
This is because static_assert
is a static (that is: compile time) assert. It does not care about the if
statement (evaluated at run-time) above.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.