繁体   English   中英

std :: is_same <A,B> :: value ==第1行为true,第2行为false

[英]std::is_same<A,B>::value == true in line 1, false in line 2

我有一个代码,其中一行返回true,另一行返回false。

例如,

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;
}

有人可以解释为什么它引发一个静态的断言错误吗?

这是因为static_assert是静态(即:编译时)断言。 它不在乎上面的if语句(在运行时评估)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM