# Vector list In a Vector list :D

This topic is 4180 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hey. I've successfully implemented a* and have a number of agents i need to keep tabs on, i have created a list of nodes to travel to for each agant.
std::vector<std::vector<void*>> agentPath;

basicly this above allows me to have a vector list again for each entity in the botPaths list.
agentPath .push_back( getAStar()->getPathList() );

Here i insert the vector list of nodes to travel to in the agentPath list. now, it is working "well sorta", but i have this on a loop for about 15 agents and somehow BotPaths.size() returns 2847 where according to me it should return 14. also the vector list inside the agentPath that contains the nodes to travel to doesnt contain the correct size either, but its size is alot more closer to what it should be rather than agentPath. I was just wondering if some1 with a bit more knowledge could possibly offer an explanation on the size of the agentPath, imo i think that each object in the list can only store a certain amount of data?? so it allocates a new agentPath entity for it, but thats wrong i know. anotehr way which i was going 2 do it, was store say the agentAPath vector list in a map or array....maybe vectors dont like being used the way i am using them? if worse comes to worse i'll add each node to be traveled to manually, 1 by one to the list but though you could to it autonomilsy like this. like if this works it will be very easy to get access to every agents list. eg:
agentPath.at(currentAgent).at(i);

thankz for reading and lending a hand. Twinsen.

##### Share on other sites
Quote:
 Original post by Twinsen2std::vector> agentPath;

That should be:
std::vector<std::vector<void*> > agentPath;

Notice the space between > and > (so it won't be mistaken for >>, like the operator std::cout uses).

Quote:
 basicly this above allows me to have a vector list again for each entity in the botPaths list.

What is botPaths? Does this mean that a single element (of std::vector<void*>) of agentPath belongs to a single agent, and the std::vector<void*> is the nodes (node is of type void*). Why don't you use a node class instead of void*? Would be much more clear.

Quote:
 agentPath .push_back( getAStar()->getPathList() );Here i insert the vector list of nodes to travel to in the agentPath list.now, it is working "well sorta", but i have this on a loop for about 15 agents and somehow BotPaths.size() returns 2847 where according to me it should return 14.

You haven't mentioned BotPaths before, so we don't know when elements are added. If you meant that agentPath.size() is 2847, then let us see the loop. Also, in case you run this multiple times, do you remember to clear() agentPath before running the loop 15 times? Also try to see what the contents of agentPath is, is it invalid data? Is it 2833 copies of the same element? What is it?

Quote:
 also the vector list inside the agentPath that contains the nodes to travel to doesnt contain the correct size either, but its size is alot more closer to what it should be rather than agentPath.

I think we need more information about getAStar()->getPathList() and the expected results before we can answer that question.

Quote:
 I was just wondering if some1 with a bit more knowledge could possibly offer an explanation on the size of the agentPath, imo i think that each object in the list can only store a certain amount of data?? so it allocates a new agentPath entity for it, but thats wrong i know.

I'm not quite sure what you say here, don't you think std::vector<T> can hold 15 elements? I can assure you, that it can.

Quote:
 anotehr way which i was going 2 do it, was store say the agentAPath vector list in a map or array....

You should solve your problem, if you don't, then you will run into the problem again in the future, when it might be harder to debug.
Quote:
 maybe vectors dont like being used the way i am using them?

No, not unless you use them in the wrong way.

Quote:
 if worse comes to worse i'll add each node to be traveled to manually, 1 by one to the list but though you could to it autonomilsy like this.like if this works it will be very easy to get access to every agents list.

Like previously said, you should really solve your problem.

Please give us all the information you have, what have you tried? What do you suspect might have happened? Give us more code to look at, etc. Describing the code is not enough, because you might have bugs you didn't realize existed.

##### Share on other sites
Quote:
Original post by CTar
Quote:
 Original post by Twinsen2std::vector> agentPath;

That should be:
std::vector<std::vector<void*> > agentPath;

Notice the space between > and > (so it won't be mistaken for >>, like the operator std::cout uses).

Not anymore. VS will correctly compile it, although I'm not certain gcc has figured it out yet. Seeing as how he's describing runtime issues, it is probably safe to assume his project is compiling.

Twinsen: I second CTar's suggestion that you provide more code.

CM

##### Share on other sites
Quote:
 Notice the space between > and > (so it won't be mistaken for >>, like the operator std::cout uses).

I'm fairly certain that std::cout does not use >> [wink]

Quote:
 Original post by Conner McCloudNot anymore. VS will correctly compile it, although I'm not certain gcc has figured it out yet.

Sorry, but this looks like C++ to me. If VS correctly compiles this, it either isn't compiling it as C++, or has a buggy C++ lexer.

Quote:
 From MSDNThe parser separates tokens from the input stream by creating the longest token possible using the input characters in a left-to-right scan.

Of course, it might be Microsoft-extended C++, at which point GCC not supporting it appears as no surprise to me. By sheer curiosity: what does the following code compile as?

template<int N> class foo {};std::vector<foo<1>>2> > vect;

Original poster: place a breakpoint on each and every line of code that appends to the incorrectly-sized vector (hopefully only a handful), and run your program. This will indicate what code is responsible for the incorrect size.

##### Share on other sites
Quote:
Original post by ToohrVyk
Quote:
 Original post by Conner McCloudNot anymore. VS will correctly compile it, although I'm not certain gcc has figured it out yet.

Sorry, but this looks like C++ to me. If VS correctly compiles this, it either isn't compiling it as C++, or has a buggy C++ lexer.

Quote:
 From MSDNThe parser separates tokens from the input stream by creating the longest token possible using the input characters in a left-to-right scan.

Of course, it might be Microsoft-extended C++, at which point GCC not supporting it appears as no surprise to me. By sheer curiosity: what does the following code compile as?

template<int N> class foo {};std::vector<foo<1>>2> > vect;

It fails to compile under VC8.
c:\...\main.cpp(22) : error C2143: syntax error : missing ';' before 'constant'c:\...\main.cpp(22) : error C2059: syntax error : 'constant'

Line 22 being the declaration of vect. Won't compile even when you disable language extensions in the project properties. You must put parentheses around 1>>2 to compile it properly.

So in short, the tried to fix a common syntax error, but broke the correct syntax.

##### Share on other sites
Quote:
 Original post by ToohrVyk...

You appear to be correct, I appologize. I was under the impression the 2003 standard remedied that particular oversight, but looking through it now I don't see any reference to such a change. Perhaps it was a proposed change for 0x I was thinking of.

CM

##### Share on other sites
hey, thankz for the replys.
Well i found and fixed the problem...lol silly me trying to blame vector lists for the problem, turns out there was a bug in my code that resulted in some wackey results, the bug was: when an agent becomes "stuck" it re-calculates the path for that bot, now this was all well and good, but i wasnt using .clear() as CTar said. so the vector list was just being added to continuesly.

thankz for helpn me solve yet again another "stupid error" they always seem to get me the little ones, lol.

sorry also for not sounding clear enough in op, i just read it then again and parts didnt make sence *wrote it at 4am in morning*.
well, thankz everyone and cheerz :D.