简体   繁体   English

唯一性数组之外的数组模板语法

[英]Array template syntax outside of unique_ptr

The syntax std::unique_ptr<T[]> can be used describe the (templated) type of a unique_ptr whose underlying raw pointer is pointing to an array of T s. 可以使用语法std::unique_ptr<T[]>来描述unique_ptr的(模板化)类型,其基础原始指针指向T s数组。 I'm wondering what the syntax T[] means generally. 我想知道T[]一般含义是什么。 Does it get used outside of smart pointers? 它是否在智能指针之外使用? Is it possible for eg vector<T[]> to ever be useful? 例如vector<T[]>是否可能有用?

It means "array of unknown bound of T ". 它的意思是“ T的未知边界数组”。 You might see such a type in function signatures: 您可能会在函数签名中看到这样的类型:

void f(int arr[]);

In a declaration of an array defined elsewhere: 在其他地方定义的数组的声明中:

extern int arr[];

And obviously, as a type parameter to a template like unique_ptr (or, some time in the future, shared_ptr too). 显然,作为诸如unique_ptr类的模板的类型参数(或将来的某个时间,也称为shared_ptr )。 It's an incomplete type, so its usefulness can be rather limited. 这是一种不完整的类型,因此其用途可能非常有限。

vector<T[]> is unlikely to be useful. vector<T[]>不太可能有用。 If you don't know how many elements are in the array, then how could you have a container of them? 如果不知道数组中有多少个元素,那么如何容纳它们呢?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM