Problems with iterator (stack-template)

P

Pascal Steiss

Hi All

I don't understand the error that g++ tells me:
---
percul3.cpp: In function `void OutputLattice(std::stack<latticeSite,
std::deque<latticeSite, std::allocator<latticeSite> > >)':
percul3.cpp:49: `iterator' is not a member of type
`std::stack<latticeSite, std::deque<latticeSite,
std::allocator<latticeSite> > >'
percul3.cpp:49: parse error before `;' token
percul3.cpp:51: `it' undeclared (first use this function)
percul3.cpp:51: (Each undeclared identifier is reported only once for
each function it appears in.)
---

It's about the code (look for the stars):
#include <sys/types.h>
#include <unistd.h>
#include <iostream>
#include <stack>
#include <iterator>
#include "time.h"
#include "stdio.h"

using namespace std;

const int sMax = 5;
const int nnn = 4;

long g[sMax+1][nnn * sMax +1];

struct latticeSite {
int x,y;
};

typedef stack<latticeSite> myStackType;

enum latticeState { _blocked, _free, _reachable };

const int latticeSize = 100;
latticeState lattice[latticeSize][latticeSize];
int originX = latticeSize / 2;
int originY = 1;

myStackType tempUntriedSites;

long loopCount = 0;

void OutputLattice(myStackType currentUntriedSites) {
cout << endl << endl << endl;
for (int y = originY+sMax; y >= 0; y--) {
cout << "|";
for (int x=originX-sMax; x<=originX + sMax; x++) {
switch(lattice[x][y]) {
case _free: cout << " "; break;
case _reachable: {
//doesn't work too...
//myStackType::iterator it_;
** stack<latticeSite>::iterator it;
** latticeSite tempSite; tempSite.x = x; tempSite.y = y;
it = find(currentUntrietSites.begin(),
currentUntriedSites.end(), tempSite);
if (it != currentUntriedSites.end()) {
cout << "X"; break;
}

}
case _blocked: cout << "B"; break;
}
cout << "|";
}
cout << endl;
}
}

Thank you
Pascal
 
R

Rolf Magnus

Pascal said:
Hi All

I don't understand the error that g++ tells me:
---
percul3.cpp: In function `void OutputLattice(std::stack<latticeSite,
std::deque<latticeSite, std::allocator<latticeSite> > >)':
percul3.cpp:49: `iterator' is not a member of type
`std::stack<latticeSite, std::deque<latticeSite,
std::allocator<latticeSite> > >'

What is it you don't understand about that? The problem is just what the
compiler said. std::stack doesn't have an iterator.
 
P

Pascal Steiss

Rolf said:
What is it you don't understand about that? The problem is just what
the compiler said. std::stack doesn't have an iterator.

f*** - I thought every container-type has an iterator.

Sorry & Thank you...
Pascal
 
J

John Harrison

Pascal Steiss said:
f*** - I thought every container-type has an iterator.

std::stack isn't a container, its a container adapter. Its puts a different
(and very limited) interface on another container, use it if it's exactly
what you need, but otherwise use a vector, list or deque.

john
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,171
Messages
2,570,935
Members
47,472
Latest member
KarissaBor

Latest Threads

Top