fork download
  1. #include <iostream>
  2. #include <typeinfo>
  3.  
  4. struct Type {};
  5.  
  6. // 1: Array of Type*.
  7. void func(Type *arr [3]) {
  8. std::cout << "Type* array.\n"
  9. << typeid(arr).name() << "\n\n";
  10. }
  11.  
  12. // 2: Array of Type&.
  13. // Illegal.
  14. // void func(Type &arr [3]) {
  15. // std::cout << "Type& array.\n"
  16. // << typeid(arr).name() << "\n\n";
  17. // }
  18.  
  19. // 3: Pointer to array of Type.
  20. void func(Type (*arr) [3]) {
  21. std::cout << "Pointer to Type array.\n"
  22. << typeid(arr).name() << "\n\n";
  23. }
  24.  
  25. // 4: Reference to array of Type.
  26. void func(Type (&arr) [3]) {
  27. std::cout << "Reference to Type array.\n"
  28. << typeid(arr).name() << "\n\n";
  29. }
  30.  
  31. int main() {
  32. // Array of Type.
  33. Type t_arr[3] = {};
  34.  
  35. // Array of Type*.
  36. Type* tp_arr[3] = { &t_arr[0], &t_arr[1], &t_arr[2] };
  37.  
  38. // Array of Type&.
  39. // Illegal.
  40. // Type& tr_arr[3] = { t_arr[0], t_arr[1], t_arr[2] };
  41.  
  42. std::cout << "Type[3]: " << typeid(t_arr).name() << "\n\n";
  43.  
  44. func(t_arr); // Calls #4.
  45. func(&t_arr); // Calls #3.
  46. func(tp_arr); // Calls #1.
  47. }
  48.  
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
Type[3]: A3_4Type

Reference to Type array.
A3_4Type

Pointer to Type array.
PA3_4Type

Type* array.
PP4Type