new运算符求解

-bootblack- -bootblack- 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
源码部分摘自<<C++ primer plus>>
template<typename Item>
class Queue
{
private:
enum {Q_SIZE = 10};
class Node
{
public:
Item item;
Node * next;
Node(const Item & i) : item(i), next(nullptr) {}
};
Node * front;
Node * rear;
int items;
....
bool dequeue(Item & item);
};

template<typename Item>
bool Queue<Item>::enqueue(const Item & item)
{
if(isfull())
return false;
Node * add = new Node(item); //这句暂时无法理解
items++;
if(front == nullptr)
front = rear = add;
else
{
rear->next = add;
rear = add;
}
return true;
}

请问大神:有注释的那个语句该如何理解啊?
小弟理解:这里的new的后面使用了(),所以这个new应该理解为是定位运算符..
()里面的是item,而item也不是一个地址啊?小弟糊涂了,恳请大神指教~~~
...全文
评论 8
收藏 已收藏
分享
返回顶部
-bootblack-
C++ 语言 65,214 成员 250,514 内容