Re: When I have a pointer to my template class, it only holds the right value in the function it was declared in..


[ Follow Ups ] [ Post Followup ] [ CS2704 Web Discussion Board ] [ FAQ ]

Posted by Daniel Longest on March 25, 2001 at 14:44:28:

In Reply to: Re: When I have a pointer to my template class, it only holds the right value in the function it was declared in.. posted by leon gunden on March 25, 2001 at 12:59:33:

Is it a requirement to allocate the array itself dynamically via new? I know the array must do its internal storage via new (that just makes sense) but is it required to allocate the array itself dynamically (which then itself does its own dynamic allocation)?

Daniel

: : That is not the exact syntax. It should be ArrayT{Author} *authorArray as a private data member of the database class, where the brackets are < and >. that part got lost when I posted. Same for my first declaration. It should be ArrayT{Author} *authorArray = new ArrayT{Author}(authorsize);
: : Does that change your answer?

: No. You are declaring a local pointer to a dynamic array object. When the function in which you are executing the above statement terminates, the pointer is destroyed and you have a memory leak. You must leave off the ArrayT{Author}* in the above statement. Just write:

: authorArray = new ArrayT{Author}(authorsize);

: in place of:

: ArrayT{Author} *authorArray = new ArrayT{Author}(authorsize);

: see if this solves your problem...





Follow Ups:



Post a Followup

Name:
E-Mail:

Subject:

Comments:

Optional Link URL:
Link Title:
Optional Image URL:


[ Follow Ups ] [ Post Followup ] [ CS2704 Web Discussion Board ] [ FAQ ]