【发布时间】:2013-08-20 04:13:59
【问题描述】:
考虑这段代码:
template <typename T>
void f()
{T x = T();}
当T = int 时,x 是否等于0 或任意值?
额外问题:因此,数组(T[N] 和 std::array<T, N>)是仅有的此类语法可能会留下具有任意值的内容的类型。
【问题讨论】:
-
0。但是,
int x;未定义。 -
关于
std::array<T,N>,您可以使用通用初始化对它们进行值初始化。 IE。std::array<int,5> data{};,但你是对的,就像固定数组一样,它们是不确定的,没有一些类型的初始值(这种方式或直接)。
标签: c++ initialization default-constructor