CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2009
    Posts
    1

    Passing Templates through Pointers

    I'm having an issue with passing templates through pointers, I managed to simplify the issue to this.

    So I have a simple template,
    Code:
    template<class T>
    class List
    {
    	public:
    		T* Arg1;
    		List(T* first){Arg1=first;}
    };
    Which I run through,
    Code:
    void GetChildren(ListProperties &properties)
    {
    	List<CPtrList> *list = new List<CPtrList>(properties.children);
    	int count = list->Arg1->GetCount();
            Test(list);
    }
    
    void Test(void *list)
    {
    	List<CPtrList>* newList = (List<CPtrList>*)list;
            int count = newList->Arg1->GetCount();
    }
    The count in GetChildren gets me 1(the correct result), whereas the count in Test gets me a number that's way off (-45030200 or something along those lines).

    Can anyone shed some light on where the problem might be?
    Last edited by starbucks99; May 14th, 2009 at 09:48 AM.

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Passing Templates through Pointers

    Can anyone shed some light on where the problem might be?
    Post a complete program, including the main() driver program that duplicates the error.

    What is ListProperties? What is it's value (it could be invalid)? When, where, and how is this code called? All of these things are not known with the code you posted.

    Regards,

    Paul McKenzie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured