可以使用using为数组键入别名吗? [英] Can using be used to type alias an array?

查看:62
本文介绍了可以使用using为数组键入别名吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定我的措词是否正确,因为这有点奇怪。
基本上,我发现了一些类似这样的代码:

I'm not sure I've worded this properly since this is a bit of an odd situation. Basically I've found some code like this:

template<class T>
struct X { typedef T Type; };

template<class T>
struct X<const T[]> { typedef T Type[]; }

我正在更改 typedef s使用类型别名语法使用C ++ 11

And I was in the process of changing the typedefs to use the C++11 using type-alias syntax when I realised this doesn't seem to work for the second example.

template<class T>
struct X<const T[]> { using Type[] = T; }

为什么?这是标准委员会的监督吗?

Why is this? Is this an 'oversight' by the standards comittee?

推荐答案

正确的语法是:

using Type = T[];

定义 Type 的类型为 T 的未知范围数组。

which defines that Type has the type "array of unknown bound of T".

这篇关于可以使用using为数组键入别名吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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