简体   繁体   English

node(){}是什么意思?

[英]What does node(){} mean?

struct node{
   int key, prior, cnt, val;
   node *l, *r;
   node(){}
   node(int nkey) : key(nkey), prior(rand()), cnt(1), l(0), r(0), val(1){}
};

What does node(){} do ? node(){}做什么的? please explain it, thank you. 请解释一下,谢谢。

它将默认构造函数node()定义为空函数{}

What does node(){} do ? node(){}做什么的? please explain it 请解释一下

node(){} looks like treap node. node(){}看起来像是陷阱节点。 Code node(){} is the syntax for defining the default constructor. 代码node(){}是用于定义默认构造函数的语法。

Without default constructor, you can't use node in stl containers like std::array , std::vector etc without extra code so you need the definition for default. 没有默认构造函数,您就无法在没有额外代码的stl容器(如std::arraystd::vector等)中使用node ,因此您需要默认的定义。 In coding competitions, people tend to write the minimal code and use the existing functionality as much as possible sometimes even at the cost of leaking scope etc. 在编码竞赛中,人们倾向于编写最少的代码,有时甚至以泄漏范围等为代价,尽可能多地使用现有功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM