您的位置:首页 > 编程语言 > C语言/C++

C++的一些常用知识(持续更新)

2017-08-10 09:21 281 查看
1 : 结构体的构造函数

struct node
{
int x,y,step;
node(int x=0,int y=0,int step=0):x(x),y(y),step(step){};
};
//这样不仅初始化好看, 也可以申请一个结构体.
int main()
{
queue<node >q;
q.push(node{0,0,0});
node t;
t.x = 0;
t.y = 0;
t.step = 0;
q.push(t);
//上面两种操作是等价的, 所以明显上面那种操作方更加好看.
}


2 : 结构体中加优先级关系的.

//就只写结构体中的东西了.
struct node
{
int x,y,step;
node(int x=0,int y=0,int step=0):x(x),y(y),step(step){};
bool operator < (const node &a) const {
return a.step < step;
}
}  //这些结构体中step小的排前面.(想多加几个元素比较加上去就行了,以a的为基准).
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: