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

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 11:24:58:

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?


: : I have declared ArrayT *authorArray; as a private data member of my database class. I initiate an object of my template class (which is ArrayT) using the declaration:

: ArrayT *authorArray = new ArrayT(authorsize);

: This is the exact syntax you used to initialize your private member? If so you have actually declared and initialized a local pointer with the same name as the private data member. This local variable "masks" the private member. When you dereference your private member, authorArray, you are dereferencing an uninitialized pointer (I assume its non-null since you didn't complain about a runtime error) and this should blow your program up (unless youre running in a weak os...)

: Use this syntax to initialize the array:

: authorArray = new ArrayT(authorsize);

: (assuming you have declared a private member in the class declaration named authorArray)

: Hope I haven't misunderstood your question...





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 ]