Hi I started a thread earlier back and I thought my problem had been solved but now new errors have popped up

Here are the errors I'm getting:
bfs.cc: In function 'void greedyMatch()':
bfs.cc:9: error: expected primary-expression before 'for'
bfs.cc:9: error: expected `)' before 'for'
bfs.cc:9: error: 'bfs_ee' was not declared in this scope
bfs.cc:9: error: 'bfs_stopA' was not declared in this scope
bfs.cc:9: error: expected `;' before ')' token
bfs_run.cc:83: error: expected `}' at end of input

The file bfs.cc is as follows:

#include <math.h>

void greedyMatch()
{
  Xnode *u;
  Ynode *v;
  arc *e;

  forallXNodes(u,G) {
    assert(!u->isMatched());
    forallOutArcs(e,u) {
#ifdef STATS
      stats.searchArcCnt++;
#endif
      v = e->head();

      if (!v->isMatched()) {
#ifdef STATS
        stats.mVal++;
        stats.greedCnt++;
        stats.flowArcCnt++;
#endif
        v->match(u);
        u->match(v);
        break;
      }
    }
  }
}

void augment(Ynode *last)
{
  Ynode *v, *v1;
  Xnode *w;
  arc *e;

  v = last;
  do
    {
      w = v->getCurrent();
#ifdef STATS
      stats.flowArcCnt++;
      stats.searchArcCnt++;
#endif
      v->match(w);
      if (w->isMatched())
        {
          v1 = w->getMatchNode();
          assert(v != v1);
          w->match(v);
          v = v1;
        }
      else
        {
          w->match(v);
          break;
        }
    }
  while (1);
#ifdef STATS
  stats.mVal++;
#endif
}

void bfsBIM(simpleQueue &Q, simpleQueue &S)
{
  Xnode *u, *w;
  Ynode *v;
  arc *e;
  bool foundPath;

  forallYNodes(v,G)
    {
      v->initialize();
#ifdef STATS
      stats.searchArcCnt++;
#endif
    }
  forallXNodes(u,G)
    {
      u->initialize();
      u->setReached(false);
#ifdef STATS
      stats.searchArcCnt++;
#endif
    }

  if (param.greedy) greedyMatch();

  forallXNodes(u,G)
    {
#ifdef STATS
      stats.searchArcCnt++;
#endif
      if (u->isMatched() || u->isReached()) continue;

      // start BFS from u
      foundPath = false;
      u->setReached(true);
      Q.enqueue(u);
      S.enqueue(u);
      do
        {
          u = Q.dequeue();
          forallOutArcs(e,u)
            {
#ifdef STATS
              stats.searchArcCnt++;
#endif
              v = e->head();
              if (v == G.getSource()) continue;
              if (v->isMatched())
                {
                  w = v->getMatchNode();
                  if (w->isReached()) continue; // includes w == u
                  assert(w != u);
                  v->setCurrent(u);
                  w->setReached(true);
                  Q.enqueue(w);
                  S.enqueue(w);
                }
              else
                {
                  foundPath = true;
                  v->setCurrent(u);
                  augment(v);
                  break;
                }
            }
        } while (!foundPath && !Q.isEmpty());

      // get ready to start new search
      Q.reinitialize();
      if (!foundPath)
        S.reinitialize(); //reached vertices remaine marked
      else
        {
          // clean up
          while (!S.isEmpty())
            {
              u = S.pop();
              assert(u->isMatched());
              u->setReached(false);
            }
        }
    }
}

The forallXnodes has been #defined in another file.This new file is visible in bfs.cc due to dependencies created by the make file .

#define forallXNodes(u,G) \ 
     (for( arc *bfs_ee=(G.getSource())->firstOutArc(),arc *bfs_stopA=\
     (G.getSource())->lastOutArc(),u=bfs_ee->head();bfs_ee<=bfs_stopA;u =\
     (++bfs_ee)->head()))

Any help shall be appreciated.......
I am using GNU g++ compiler.

Thanks,guys.

I strongly suggest trying to narrow the code down to the smallest piece that will give you that compiler error. From what you've posted, I can't tell that Xnode, Ynode, and arc are defined anywhere that the compiler should know about.

Why are you using this ghastly define? Why not make it a normal function?

Dave

Too many parentheses, says Ed. ;) Look at the expansion of the macro and you will see something like the following.

(for (<init>; <condition>; <increment>))
{
    <body>
}

Control flow statements are not expressions that can be wrapped in parentheses.

You can see what the macro expands to with

g++ -E filename.cpp>testfile

but again, why not just write the function? Have you really noticed a speed difference?

Dave

Hmm... Do you still need function prototype to be declared on the top of the file too??? Can't really remember...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.