C ++:变量声明初始化顺序 [英] C++: variable declaration initialization order

查看:112
本文介绍了C ++:变量声明初始化顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我定义这样的一些变量:

  int a = pop(),b = pop c = pop(); C ++保证 a 



首先要初始化,然后 b ,然后 c

[dcl.decl] / 3表示


$ b $ b


-3-每个声明中的init-declarator单独分析,就像它在一个声明中一样。


这意味着你的代码被视为:

  int a = pop 
int b = pop();
int c = pop();


When I'm defining some variables like this:

int a = pop(), b = pop(), c = pop();

does C++ give a guarantee that a is going to be initialized first, then b and then c? or is the order not defined?

解决方案

[dcl.decl]/3 says

-3- Each init-declarator in a declaration is analyzed separately as if it was in a declaration by itself.

Which means your code is treated like:

int a = pop();
int b = pop();
int c = pop();

这篇关于C ++:变量声明初始化顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆