“nullptr”之前的预期不合格 ID
Expected unqualified-id before ‘nullptr’
我尝试实施 BST,但 std::nullptr
显示错误:
error: expected unqualified-id before ‘nullptr’
#include <iostream>
#include <memory>
template <typename T>
class BinTreeNode {
public:
BinTreeNode(T key): data {key} {
left = std::nullptr;
right = std::nullptr;
}
~BinTreeNode() {}
T data;
BinTreeNode<T>* left;
BinTreeNode<T>* right;
};
template <typename T>
class BinTree {
public:
BinTree(){
root = std::nullptr;
}
~BinTree() {}
BinTreeNode<T>* root;
};
int main(){
BinTree<int> tree;
}
我尝试在 Google 中搜索它,但没有找到与 std::nullptr
相关的任何有意义的内容
nullptr
, unlike nullptr_t
, does not need std::
prefix。这样做的原因是 nullptr 是一个文字,并且没有在命名空间 std
中定义,同样 42 也没有在那里定义。它也不需要使用任何包含指令。
另一方面,nullptr_t
是一种类型,在命名空间 std
中定义,需要包含 <cstddef>
。
我尝试实施 BST,但 std::nullptr
显示错误:
error: expected unqualified-id before ‘nullptr’
#include <iostream>
#include <memory>
template <typename T>
class BinTreeNode {
public:
BinTreeNode(T key): data {key} {
left = std::nullptr;
right = std::nullptr;
}
~BinTreeNode() {}
T data;
BinTreeNode<T>* left;
BinTreeNode<T>* right;
};
template <typename T>
class BinTree {
public:
BinTree(){
root = std::nullptr;
}
~BinTree() {}
BinTreeNode<T>* root;
};
int main(){
BinTree<int> tree;
}
我尝试在 Google 中搜索它,但没有找到与 std::nullptr
nullptr
, unlike nullptr_t
, does not need std::
prefix。这样做的原因是 nullptr 是一个文字,并且没有在命名空间 std
中定义,同样 42 也没有在那里定义。它也不需要使用任何包含指令。
另一方面,nullptr_t
是一种类型,在命名空间 std
中定义,需要包含 <cstddef>
。