Why won't this compile and how can it be implemented so that it does?

后端 未结 6 803
挽巷
挽巷 2020-12-21 12:30

Here is some C++ code I\'m playing around with:

#include 
#include 

#define IN ,
#define FOREACH(x,y) for(unsigned int i=0;i&l         


        
6条回答
  •  萌比男神i
    2020-12-21 12:50

    The preprocessor doesn't expand the IN to a comma until after it reads the arguments to FOREACH.

    I'm pretty sure that the c++ preprocessor is one pass only, so you'll have to use:

    FOREACH(int item, ints)
        cout << item;
    ENDFOREACH
    

提交回复
热议问题