troubleshooting Question

How to add a new object in a dynamic array in C++

Avatar of PiaPia
PiaPiaFlag for Sweden asked on
C++
16 Comments1 Solution590 ViewsLast Modified:
Hi, I have trouble with adding a new object in a dynamic array. When compiling my program I get a warning stating that "Warning W8004...: 'temp' is assigned a value that is never used in function TransaktionsLista::laeggTill(Transaktion &)". But where have I gone wrong in my code (or in my head)?
Please keep it simple as I'm new to programming.
void TransaktionsLista::laeggTill ( Transaktion &t )
{	
  if ( antalTrans > 0 ) 
  {
    Transaktion *temp = 0 ;
    temp = new Transaktion[antalTrans+1] ;
    for ( int i = 0; i < antalTrans; i++ )
      temp[i] = trans[i] ;
      temp[antalTrans] = t ;
      delete [] trans ;
      trans = temp ;
      antalTrans++ ;
  }
  else 
  {
    trans = new Transaktion[1] ;
    trans[0] = t ;
    antalTrans++ ;
  }	
}
ASKER CERTIFIED SOLUTION
stsanz

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 16 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 16 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros