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 leon gunden on March 25, 2001 at 12:59:33:

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 Anuj on March 25, 2001 at 11:45:23:

: 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 ]