fork download
  1.  
  2. #include <iostream>
  3.  
  4. template <typename theType, size_t theSize>
  5. char (& AsArray(theType (&) [theSize])) [theSize];
  6.  
  7. int main(int argc, char * argv[])
  8. {
  9. struct { int i; double d; } array[10];
  10. double * notAnArray;
  11.  
  12. // Funktioniert.
  13. std::cout << sizeof(AsArray(array)) << std::endl;
  14.  
  15. // Funktioniert.
  16. std::cout << sizeof(array) / sizeof(array[0]) << std::endl;
  17.  
  18. // Funktioniert nicht; soll es auch nicht!
  19. // std::cout << sizeof(AsArray(notAnArray)) << std::endl;
  20.  
  21. // Funktioniert; undefiniertes Verhalten.
  22. std::cout << sizeof(notAnArray) / sizeof(notAnArray[0]) << std::endl;
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0s 2928KB
stdin
Standard input is empty
stdout
10
10
0