问题描述
c ++ 11中的auto命令是静态绑定(打字)还是动态绑定?
如果我有这个代码
auto x = 5;
编译器会确定x是一个int还是将在运行时解析? / p>
此外,以下代码中x的类型是什么?
auto x = 5,y = 4.5
称为类型推断。输入仍然是 static ,但是让编译器确定表达式的类型。
具体 auto x = 5;
,在编译时,。因为这个原因,你总是在初始化时提供一个明确的表达式。例如 auto x;
。
Is auto command in c++11 is static binding(typing) or dynamic binding?
i.e. if i have this code
auto x = 5;
will the compiler decide that "x" is a int, or will it be descovered on runtime?
also, what will be the type of x in the following code?
auto x = 5, y = 4.5
This is called type inference. The typing is still static, but you leave the compiler figure out what the type of an expression is.
Specifically auto x = 5;
, at compiler time, is translated to int x = 5;
. For this very reason you have always to provide an unambiguous expression at initialization. For example auto x;
wouldn't work.
这篇关于auto在c ++ 11是静态类型或动态类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!