1

In my TeamMatcher.C, I have the following bit of code:

void TeamMatcher::makeTeamSet(){                                                                                                          
  //Segmentation fault here:                                                                                                               
    Team tempTeam(rosterExcellent[0]);
  //...more code in this method below this point, but it has all been commented out.

rosterExcellent is a vector

Here is the constructor for Team(Student member1):

Team::Team (Student member1)
{
  // members is a vector<Student> instance variable in Team
  // commonHrsAvailable is a vector<int> in Team


  // members.push_back(member1);                                                                                                                                  
  //commonHrsAvailable = member1.hrsAvailable;                                                                                                                   
  //numberOfCommonHrsAvailable = commonHrsAvailable.size();                                                                                                       
}

Notice all the lines are commented out and I still get the segmentation fault. This is the last bit of code to be executed.

Now, I messed around changing members to vector, changing this constructor's parameter to a Student*, and the rosterExcellent to vector (as well as changing the . notation to -> where appropriate). I got it to the point where it would run the first line of the constructor (members.push_back(member1)), but it seg faulted on the next line (even after I changed to -> notation).

6
  • 5
    Is it possible that rosterExcellent is a null pointer or an empty vector? Commented Jan 19, 2012 at 17:23
  • 3
    What's in rosterExcellent? Is it instantiated and does an element exist at position 0? Commented Jan 19, 2012 at 17:23
  • 1
    Show us the Student's copy constructor and destructor. Commented Jan 19, 2012 at 17:24
  • OMGOIH@#ORIFHEOFHEIEFWH:!!! What a noob move! Thank you! runs away in shame Can close this as that was a pretty noob mistake! Commented Jan 19, 2012 at 17:24
  • 1
    Actually, I'd recommend against closing it. It will probably be helpful to others, but only if you can provide a little more detail as to the problem you discovered... was rosterExcellent indeed null or empty? Commented Jan 19, 2012 at 17:29

1 Answer 1

1

rosterExcellent[0] is either NULL or not initialized properly.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.