c++ - 为什么 std::is_assignable 使用相关的指针类型返回 false?

标签 c++ c++14 typetraits

给定两个非常简单的类:

class X
{
};

class Y : public X
{
};

为什么会这样,使用 Clang 和 GCC targeting C++14 , std::is_assignable<X*, Y*>::valuefalse ?是true当我以 C++11 为目标时,在我的设置中使用 Clang。

最佳答案

这是因为在您的情况下 X* 成为右值。您不能分配给右值。改为左值:

std::is_assignable<X*&, Y*>::value
//                  ~^~

关于c++ - 为什么 std::is_assignable 使用相关的指针类型返回 false?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32893374/

相关文章:

c++ - 逆向工程和理解复杂软件的最有效方法是什么?

c++ - 常量和非常量版本和继承

c++ - 使用 bcrypt 哈希密码进行身份验证

c++ - SDL2 运行得太快了——为什么当我只按一个按钮时它会读取多个输入?

C++ : union of two types without virtual base class inheritance

c++ - 如何检查模板模板参数类型的唯一性?

C++模板类,模板成员友元函数匹配规则

c++ - 在 CRTP : type of Derived is not complete (yet) 中继承 Derived 的 type_trait

c++ - 临时/"non-addressable"固定大小数组?

compiler-errors - 我开始评论我的C++程序,然后出现错误