Tuesday 27 March 2018

c++11 - Strange declaration with using in C++



On a piece of code in a previous question in stackoverflow I saw this, strange to me, declaration with using:



template  
class A

{
public:
...
using const_buffer_t = const char(&)[SIZE];
...
};


Could someone please address the following questions:





  1. What type it represents?

  2. Where do we need such kind of declarations?


Answer



That's a type alias, a new syntax available since c++11.



What you're actually doing is typedefing the type of an array



const_buffer_t 



will be an array of const char with length = SIZE


No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...