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 ...
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.:)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With