问题标签 [nullptr]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
1042 浏览

c++ - C ++ 11 Setter函数参数传递nullptr

我想知道关于参数传递 nullptr 的 C++11 最佳实践。我想通过将 nullptr 传递给已经存在的 setter 函数来重置类成员对象。举个简单的例子:

这个可以吗?或者,或者有更好、更首选的方法来重置 my_foo?我不想仅仅为了重置 my_foo 而创建另一种方法。

我正在处理的应用程序的真正动机是我有一个由可变数量的其他类共享的持久单例类。对于那些其他类来说,为了编码目的,在他们需要的持续时间内简单地拥有一个指向该单例的共享指针并使用它,然后在他们不再被允许访问它时丢弃/设置为 nullptr 是很方便的。如果有什么我可能遗漏或没有想到的,任何建议都非常感谢,谢谢!

0 投票
2 回答
3433 浏览

c++ - C ++将char指针设置为null

在 Visual Studio 2012 中,我在搞乱指针,我意识到这个程序一直在崩溃:

我的意图是将 a 设置pointernullptr,然后打印地址。即使程序可以编译,它也会在运行时崩溃。有人可以解释发生了什么吗?

pointer另外,和有什么区别*pointer

0 投票
2 回答
6456 浏览

c++ - What is the type of nullptr?

The Standard states, that nullptr is a pointer literal of type std::nullptr_t (2.14.7). And 18.2p9 defines nullptr_t by

By 7.1.6.2p4 decltype(nullptr) is the type of the expression nullptr, which is by definition std::nullptr_t (since the expression nullptr is a prvalue). Substituting that into the definition of nullptr_t results in

On the other hand a typedef specifier does not introduce a new type, it's just a name for another existing type. So, what is exactly nullptr_t? I'm not able to comprehend these definitions.

0 投票
1 回答
185 浏览

.net - when we need to pass nullptr to an object^ or EventArgs ? and why to pass EventArgs::Empty to EventArgs^?

I have a method in my code, it's name is bindingSource_PositionChanged. the definition of it is:

#xA;

My questions:

  1. I have in my program calling the function in this way:

    #xA;

    my Question 1: what makes pass System::EventArgs::Empty to the parameter e of this function? or to any System::EventArgs^. and what makes pass nullptr to the parameter sender here? or to any System::Object^ sender?

  2. I have in my program calling the function in another way:

    #xA;

    Question 2: what makes a nullptr to the parameter e of this function? or to any parameter of the type System::EventArgs^?

0 投票
2 回答
6135 浏览

c++ - 无法将 nullptr 返回到我的 C++ 类

在我课堂上的方法中,我正在检查一个值是否为 0 以返回nullptr,但我似乎无法做到这一点。

我得到的错误是:could not convert 'nullptr' from 'std::nullptr_t' to 'Complex'

我现在意识到,那nullptr是指针,但是,我的对象不是指针,有没有办法将它设置为 null 或类似的东西?

0 投票
1 回答
172 浏览

c++ - 模板将运算符转换为指向成员函数语法的指针的工作原理

我正在查看nullptr 的模拟版本,并看到了这个转换运算符(nullptr_t 的成员):

这种指向成员函数的语法让我感到困惑。我通常希望看到这样的类型

使用上面的模板,没有输入参数。在这种情况下,我无法弄清楚类型推导是如何工作的。我很难形成一个特定的问题,除了,这是如何工作的?如果我有这样的代码:

我猜 T 推断为 int,而 C 推断为 MyClass。什么“发生”浮动?

0 投票
1 回答
6075 浏览

c++ - 检查是否将 std::function 分配给 nullptr

我想知道是否有任何方法可以检查您分配给 an 的函数指针是否std::functionnullptr. 我期待!-operator 这样做,但它似乎只在函数被分配了 type 的东西时才起作用nullptr_t

我写了这个辅助函数来解决这个问题。

0 投票
2 回答
10471 浏览

c++11 - 应该在 nullptr 分配上使用 std::move 吗?

我遇到了以下情况。在 nullptr 上移动有什么好处吗?我认为它基本上是为 Node* 分配一个零,所以我不确定在这里移动是否有任何优势。有什么想法吗?

0 投票
2 回答
108 浏览

c++ - 手动删除函数返回的指针

假设我有这个代码。

我应该删除'x'(如果它不是nullptr)吗?据我所知,我们应该只释放使用运算符“new”分配的内存。这当然不是这里的情况。

0 投票
4 回答
5524 浏览

c++ - 检查结构中的指针是否为空

我有一个非常简单的结构

我试图总是添加到不为空的 pNext 中。

当我调用 add(10); 第一次,它将头指针设置为实例化节点。但是当我再次调用该方法时 add(9); 我收到“访问冲突读取位置 0xCDCDCDCD”。

我的问题是,我如何检查 pNext 节点是否分配了地址?我尝试使用 == nullptr 但无济于事。