#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    10
    Rep Power
    0

    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.
  2. #2
  3. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    243
    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).

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    10
    Rep Power
    0
    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);
  6. #4
  7. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    243
    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.

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    10
    Rep Power
    0
    numMigracion is just an integer. Is just the size of the vector.
  10. #6
  11. I'm Baaaaaaack!
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jul 2003
    Location
    Maryland
    Posts
    5,538
    Rep Power
    243
    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!

    My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
    Free code: http://sol-biotech.com/code/.
    Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
    Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
    LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw

IMN logo majestic logo threadwatch logo seochat tools logo