August 24th, 2003, 10:36 AM
-
STL Vector issues
I got a problem with STL vectors. I haven an array of structures like this:
struct s
{
vector <Sometype *> vect;
[...]
};
During inicialization I try to do a
s.vect=vector<Cromosoma*>::vector(aSize);
When I compile under windows I got no problem but when I try under Linux I get a segmentation fault error.
Why?
Thanks in advance.
August 24th, 2003, 01:48 PM
-
I am a little surprised it compiled on either platform as you are stuffing a "Cromosoma*" into an object declared "Sometype *" (unless you were just throwing some stuff in an example). Please show your exact code (enclosed in "code" tags please).
August 24th, 2003, 03:31 PM
-
I changed the types to be more legible because code is in spanish ;)
exactly the code is:
Code:
struct mensaje
{
vector <Cromosoma *> individuos;
bool valido;
};
And the segfault goes in the second line
Code:
mensaje mensEntrada;
mensaEntrada.individuos = vector<Cromosoma *>::vector(numMigracion);
August 24th, 2003, 05:16 PM
-
What is the definition of "numMigracion"? I am not that much of a C++ guru, your code doesn't make much sense to me. Is numMigracion already a vector<Cromosoma *> populated with data?
Try breaking the code down into as many peices as you can on separate lines and see what line causes the crash.
August 24th, 2003, 06:03 PM
-
numMigracion is just an integer. Is just the size of the vector.
August 24th, 2003, 09:35 PM
-
I'm sorry, nothing is coming to mind. The only suggestion I can make is to make a minimal program that exhibits the exact same behavior and post it so I can tinker with it. I have never tried the technique you are using so am unfamiliar with it.
However, I have had mysterious crashes before that as I stripped away other code I 'accidentally' found another problem (usually corruption of memory) that, when fixed, cause the first problem to go away. Try to make a 10-15 line program to reproduce the same error, maybe you will find the problem is somewhere else.
Good luck!