Why can't I use this 'void' type in a range based for loop?

sparsh goyal
for(auto i: {{1,2,3}, {4,5,6}, {7,8,9}}){
    /* loop body */
}

I know I have other ways to get my work done. But I was just wondering why we cannot use such type of list in this loop.

It is giving me this error:

cannot use type 'void' as a range
Jarod42

{..} has no types, so it is problematic for deduction needed for inner type, you might help by explicitly provide the type: (I used CTAD from C++17 here, before add <int>)

for (auto i: {std::initializer_list{1,2,3}, {4,5,6}, {7,8,9}}){
    /* loop body */
}

Demo

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Why can't I use for in makefile on Windows?

분류에서Dev

What is the (void*) type? And how can I dereference it?

분류에서Dev

Why can't I use js2coffee to convert `$`?

분류에서Dev

Why can't I use the first or last address in a subnet?

분류에서Dev

Why can't I use SSH with these firewall rules? [WINDOWS HOST]

분류에서Dev

Range based for loop - why are these begin/end functions not found?

분류에서Dev

Method returning container for use in range-based for loop

분류에서Dev

why do I have to declare an irrelevant struct file_handle variable before I can use that type?

분류에서Dev

Why I can't type any letter if I separate the .js file?

분류에서Dev

Why do i have to use a for loop and not a foreach loop?

분류에서Dev

SQL Server 2008 - Why can't I use WHERE on query from select count(*) as

분류에서Dev

Why can't I use the same host name for two dual-boot OS on the same machine?

분류에서Dev

Why can't I see gnome extensions?

분류에서Dev

Why I can't rotate the Player transform?

분류에서Dev

Why can't I pgrep a process?

분류에서Dev

Why can't I draw elements to the stage?

분류에서Dev

Why can't I create a Jenkins account?

분류에서Dev

Why I can't select MF?

분류에서Dev

Why can't I write to the file mmaped

분류에서Dev

Why can't I delete this directory?

분류에서Dev

Why can't I change the value in GridView?

분류에서Dev

Why can't I read whole file?

분류에서Dev

Why can't I write to this buffer?

분류에서Dev

Why can't I rename shapes in Visio?

분류에서Dev

Can't use a particular variable within a nested for loop?

분류에서Dev

Why can't I execute a script I created

분류에서Dev

How can I use True Type Collection (.ttc) in JavaFX?

분류에서Dev

Why does my Xcode compiler tell me I use a value type even though I use classes?

분류에서Dev

Haskell RethinkDB insert can't return the type I want?

Related 관련 기사

  1. 1

    Why can't I use for in makefile on Windows?

  2. 2

    What is the (void*) type? And how can I dereference it?

  3. 3

    Why can't I use js2coffee to convert `$`?

  4. 4

    Why can't I use the first or last address in a subnet?

  5. 5

    Why can't I use SSH with these firewall rules? [WINDOWS HOST]

  6. 6

    Range based for loop - why are these begin/end functions not found?

  7. 7

    Method returning container for use in range-based for loop

  8. 8

    why do I have to declare an irrelevant struct file_handle variable before I can use that type?

  9. 9

    Why I can't type any letter if I separate the .js file?

  10. 10

    Why do i have to use a for loop and not a foreach loop?

  11. 11

    SQL Server 2008 - Why can't I use WHERE on query from select count(*) as

  12. 12

    Why can't I use the same host name for two dual-boot OS on the same machine?

  13. 13

    Why can't I see gnome extensions?

  14. 14

    Why I can't rotate the Player transform?

  15. 15

    Why can't I pgrep a process?

  16. 16

    Why can't I draw elements to the stage?

  17. 17

    Why can't I create a Jenkins account?

  18. 18

    Why I can't select MF?

  19. 19

    Why can't I write to the file mmaped

  20. 20

    Why can't I delete this directory?

  21. 21

    Why can't I change the value in GridView?

  22. 22

    Why can't I read whole file?

  23. 23

    Why can't I write to this buffer?

  24. 24

    Why can't I rename shapes in Visio?

  25. 25

    Can't use a particular variable within a nested for loop?

  26. 26

    Why can't I execute a script I created

  27. 27

    How can I use True Type Collection (.ttc) in JavaFX?

  28. 28

    Why does my Xcode compiler tell me I use a value type even though I use classes?

  29. 29

    Haskell RethinkDB insert can't return the type I want?

뜨겁다태그

보관