fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <cctype>
  5. #include <cstdlib>
  6. #include <stdexcept>
  7. #include <initializer_list>
  8.  
  9. using namespace std;
  10.  
  11. using string_arr = string[10];
  12.  
  13. string s[10] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"};
  14. int odd[] = {1, 3, 5, 7};
  15. int even[] = {0, 2, 4, 6};
  16.  
  17. string (&f())[10]
  18. {
  19. return s;
  20. }
  21.  
  22. string_arr& f1() { return s; }
  23.  
  24. auto f2() -> string_arr&
  25. {
  26. return s;
  27. }
  28.  
  29. decltype(s) &f3() { return s; }
  30.  
  31. decltype(odd) &g(int i)
  32. {
  33. return (i % 2) ? even : odd;
  34. }
  35.  
  36.  
  37. int main(int argc, char *argv[])
  38. {
  39. auto x = f3();
  40. auto y = g(2);
  41.  
  42. for (int i = 0; i < 10; ++i)
  43. cout << *(x + i) << " ";
  44. cout << endl;
  45. for (const auto i : y) cout << i << endl;
  46. }
  47.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main(int, char**)':
prog.cpp:45:29: error: 'begin' was not declared in this scope
         for (const auto i : y) cout << i << endl;
                             ^
prog.cpp:45:29: note: suggested alternatives:
In file included from /usr/include/c++/5/string:51:0,
                 from /usr/include/c++/5/bits/locale_classes.h:40,
                 from /usr/include/c++/5/bits/ios_base.h:41,
                 from /usr/include/c++/5/ios:42,
                 from /usr/include/c++/5/ostream:38,
                 from /usr/include/c++/5/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/5/bits/range_access.h:87:5: note:   'std::begin'
     begin(_Tp (&__arr)[_Nm])
     ^
/usr/include/c++/5/bits/range_access.h:87:5: note:   'std::begin'
prog.cpp:45:29: error: 'end' was not declared in this scope
         for (const auto i : y) cout << i << endl;
                             ^
prog.cpp:45:29: note: suggested alternatives:
In file included from /usr/include/c++/5/string:51:0,
                 from /usr/include/c++/5/bits/locale_classes.h:40,
                 from /usr/include/c++/5/bits/ios_base.h:41,
                 from /usr/include/c++/5/ios:42,
                 from /usr/include/c++/5/ostream:38,
                 from /usr/include/c++/5/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/5/bits/range_access.h:97:5: note:   'std::end'
     end(_Tp (&__arr)[_Nm])
     ^
/usr/include/c++/5/bits/range_access.h:97:5: note:   'std::end'
stdout
Standard output is empty