Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use 'using' to declare reference to 3 integers type alias?

I have been given an exercise where I need to use a type alias for a 'reference to 3 integers'. Although I found success using typedef I'm not able to replicate it by using introduced by c++11.

Code :

typedef int (& int_ref)[3]; \\success

using int_ref2 = (int &) [3]; \\error

Should I then just use something like ...

using int_ref2 = int [3];

int_ref2 & iruvar ...

like image 214
Zaid Khan Avatar asked Dec 11 '15 14:12

Zaid Khan


Video Answer


1 Answers

Compare these two declarations

typedef int (& int_ref)[3]; \\success

using int_ref2 =  (int &) [3]; \\error 

As you can see there is a difference: in the second declaration type specifier int is inside the parentheses.

So place it outside the parentheses

using int_ref2 =  int( & )[3];

All you need is to move the type name used in the typedef outside the parentheses to the left side relative to the equation sign.

The advantage of using the using declaration is that it has more strict and clear style.

Compare it for example with the following typedef declaration

int typedef (& int_ref)[3];

that is also a valid declaration.:)

like image 120
Vlad from Moscow Avatar answered Nov 09 '22 20:11

Vlad from Moscow