未初始化向量的值< int> [英] C++ - value of uninitialized vector<int>

查看:105
本文介绍了未初始化向量的值< int>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从这个问题,全局/静态未初始化的int的值将为0.对这一个说,对于向量,将调用对象类型的默认构造函数。

I understand from the answer to this question that values of global/static uninitialized int will be 0. The answer to this one says that for vectors, the default constructor for the object type will be called.

I我无法弄清楚 - 当我有向量< int> v(10) int 的默认构造函数是什么?如果我有向量< int> v(10)全局声明?

I am unable to figure out - what happens when I have vector<int> v(10) in a local function. What is the default constructor for int? What if I have vector<int> v(10) declared globally?

我看到的是 vector< int& v(10)在一个局部函数导致变量为0 - 但我不知道这是否只是因为我的编译器或是固定的预期行为。

What I am seeing is that vector<int> v(10) in a local function is resulting in variables being 0 - but I am not sure if that is just because of my compiler or is the fixed expected behaviour.

请注意,此行为与局部变量(例如 int x; )不同,这会使值未初始化C语言,行为是继承自)。

Note that this behavior is different from a local variable such as int x; which leaves the value uninitialized (as in the C language that behavior is inherited from).

这篇关于未初始化向量的值&lt; int&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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