Задать вопрос
  • Почему не работает оператор for each в C++?

    @alikhan_hero Автор вопроса
    Adamos, если поставить auto вместо int - результат был тот же самый. Внутренний for each вызывал ошибку
    Написано
  • Почему не работает оператор for each в C++?

    @alikhan_hero Автор вопроса
    Я оставил только ошибки относящиеся к приведенному коду.

    test.cpp: In function ‘int main()’:
    test.cpp:23:31: error: invalid conversion from ‘int*’ to ‘int’ [-fpermissive]
       23 |         for (int subnumbers : numbers)
          |                               ^~~~~~~
          |                               |
          |                               int*
    test.cpp:25:33: error: ‘begin’ was not declared in this scope; did you mean ‘std::begin’?
       25 |                 for (auto num : subnumbers) {
          |                                 ^~~~~~~~~~
          |                                 std::begin
    In file included from /usr/include/c++/11/string:54,
                     from /usr/include/c++/11/bits/locale_classes.h:40,
                     from /usr/include/c++/11/bits/ios_base.h:41,
                     from /usr/include/c++/11/ios:42,
                     from /usr/include/c++/11/ostream:38,
                     from /usr/include/c++/11/iostream:39,
                     from test.cpp:1:
    /usr/include/c++/11/bits/range_access.h:108:37: note: ‘std::begin’ declared here
      108 |   template<typename _Tp> const _Tp* begin(const valarray<_Tp>&) noexcept;
          |                                     ^~~~~
    test.cpp:25:33: error: ‘end’ was not declared in this scope; did you mean ‘std::end’?
       25 |                 for (auto num : subnumbers) {
          |                                 ^~~~~~~~~~
          |                                 std::end
    In file included from /usr/include/c++/11/string:54,
                     from /usr/include/c++/11/bits/locale_classes.h:40,
                     from /usr/include/c++/11/bits/ios_base.h:41,
                     from /usr/include/c++/11/ios:42,
                     from /usr/include/c++/11/ostream:38,
                     from /usr/include/c++/11/iostream:39,
                     from test.cpp:1:
    /usr/include/c++/11/bits/range_access.h:110:37: note: ‘std::end’ declared here
      110 |   template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept;
          |                                     ^~~
    Написано