0

Trying to just copy one object array to a second array minus first item in array (which I don't believe should matter). (First array 33 items and 2nd array has 32). Nothing is copying over. 2nd array has constructor values when printed after function. Am I not "pointing" correctly? I don't have a good grasp of pointers or *this operator. My other overload functions appear to work fine. I am copying to drop the first member of the array because when I sort, I cannot get the sort correct (it includes the first). So I am trying to find my issue with that process in this manner and have found that my copy is not working.

Print first array - values good. Make copy and print of second has constructor values. Been searching/reading across Internet. Stumped. Other object functions working fine. I am having trouble getting proper formatting of code...sorry.

` Team* Tm; Tm = new Team[33];

Team* Tm2;
Tm2 = new Team[33];

for (int j = 1; j < NumberOf.GetNumTeamsNFL() + 1; ++j) {
    Tm[j] = Tm2[j-1];
}// End of copy to Tm2[]
Team Team::operator=(Team & Tm)
{
 Base::operator=(Tm);
 Position = (Tm.GetPosition());
 GamesPlayd = (Tm.GetGamesPlayd());
 wins = (Tm.GetWins());
 loss = (Tm.GetLoss());
 ties = (Tm.GetTies());
 DivWins = (Tm.GetDivWins());      
 DivLoss = (Tm.GetDivLoss());     
 DivTies = (Tm.GetDivTies());     
 ConfWins = (Tm.GetConfWins());   
 ConfLoss = (Tm.GetConfLoss());   
 ConfTies = (Tm.GetConfTies());   
 ptsscrd = (Tm.GetPtsScored());
 ptsalwd = (Tm.GetPtsAllowd());
 ofr = (Tm.GetOfr());
 dfr = (Tm.GetDfr());
 PlayOffPoints = (Tm.GetPlayOffPoints());
 PlayOffSeed = (Tm.GetPlayOffSeed());
 WLTPercentage = (Tm.GetWLTPercentage());
 return *this;
}// End of operator= overload.`
2
  • Which programming language are you using? Commented Jan 12, 2024 at 17:05
  • You are initializing both Tm and Tm2 arrays, but you are copying from Tm2 to Tm, which will result in data loss as Tm is overwritten with Tm2. Additionally, you should be using the = operator to copy objects, not the assignment operator =. Commented Jan 12, 2024 at 17:12

1 Answer 1

0

I found my issue after days of looking and trying different ideas. I was copying the new to the old not old to new object. I don't know how to close the question.

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

1 Comment

I think you can just delete it. But I think that you typed an answer it might not let you until you delete that answer and pray no one else submits one in that timeframe.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.