By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,002 Members | 2,137 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,002 IT Pros & Developers. It's quick & easy.

Problems with iterator (stack-template)

P: n/a
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
Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Pascal Steiss wrote:
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.

Jul 22 '05 #2

P: n/a
Rolf Magnus schrieb:
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.


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

Sorry & Thank you...
Pascal
Jul 22 '05 #3

P: n/a

"Pascal Steiss" <_-**********************@gmx.ch> wrote in message
news:2j*************@uni-berlin.de...
Rolf Magnus schrieb:
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.


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
Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.