Using c++ typedef/using type alias

后端 未结 3 830
不知归路
不知归路 2021-01-03 21:59

I am reading C++ primer book and completely don\'t understand one line:

 using int_array = int[4]; 
 typedef int int_array[4]; // This line
 for (int_array *         


        
3条回答
  •  迷失自我
    2021-01-03 22:19

    This line does nothing as it is redundant

    The lines

    using int_array = int[4];
    

    and

    typedef int int_array[4];
    

    do the same thing. See reference for using and typedef. You can leave one or the other out and the behaviour is the same. It is not an error to have two different declarations, as they are not conflicting (they do the exact same thing).

    The first way of doing it (using the using keyword) was introduced with C++11 and is in my opinion easier to read, so I prefer it over the typedef version.

提交回复
热议问题