converting c code to c++, the foreach statement

This is a discussion on converting c code to c++, the foreach statement within the C++ Programming forums, part of the General Programming Boards category; So I need to make use of a library which is written in C and I'm having a little trouble ...

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    3

    converting c code to c++, the foreach statement

    So I need to make use of a library which is written in C and I'm having a little trouble integrating it with c++. Anyhow the code makes use of a foreach statement but it seems to not get along with c++ that well, I've found numerous different pages explaining how to use the foreach in c++, unfortunately none of them work. Anyhow this is what theirs is looking like, this is c code mind you:

    Code:
    FOREACHvertex_(vertices)
    {
         do some more stuff; blah blah blah
    }
    My code looks the same, which is probably a problem as mine is c++. I get 2 different errors and I can't deduce what is causing each, an "error: FOREACHvertex not defined in this scope" and "error: vertex not defined in this scope". So if someone could explain the foreach I guess that would help loads, or point me to a page that gives the correct explanation. I'm using g++ and I have a premonition that the syntax might be slightly affected by compiler.

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    I guess FOREACHvertex() might be a macro, so you could just replace it with
    Code:
    for (int i = 0; i < vertices; i++)
    Or you could take a look at for_each algorithm .

  3. #3
    Registered User
    Join Date
    Jul 2006
    Posts
    3
    Turns out it's neither, FOREACHvarname is actually an explicitly defined function, that only took forever to figure out, if I understood better I'd explain more. Thanks anyhow.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 10-31-2005, 11:36 AM
  2. how do I morse code converting program
    By panfilero in forum C Programming
    Replies: 17
    Last Post: 10-29-2005, 10:16 PM
  3. True ASM vs. Fake ASM ????
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-02-2003, 04:28 AM
  4. Seems like correct code, but results are not right...
    By OmniMirror in forum C Programming
    Replies: 4
    Last Post: 02-13-2003, 01:33 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 06:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21