gpt4 book ai didi

c++ - 为什么 nullptr_t 不能分配给 int*?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:42:45 27 4
gpt4 key购买 nike

<分区>

cout << std::is_assignable<int*, std::nullptr_t>::value << endl;
cout << std::is_assignable<int*&, std::nullptr_t>::value << endl;

输出为:0 1

我不明白为什么第一次检查返回false

我可以将 nullptr 分配给一个对指针的引用,但我不能将它分配给一个原始的指针

反之亦然!

int* p = nullptr;
int*& pref = nullptr;

如预期的那样,第二个赋值标记了一个错误:

error: cannot bind non-const lvalue reference of type int*& to an rvalue of type int*

谁能给我解释一下这是怎么回事?

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com