Can using be used to type alias an array?

你。 提交于 2019-12-24 01:53:48

问题


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[]; }

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.

i.e. it isn't possible to do:

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

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


回答1:


The right syntax is:

using Type = T[];

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



来源:https://stackoverflow.com/questions/43013243/can-using-be-used-to-type-alias-an-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!