CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Now what's wrong with this STL code

    Same code as last thread but different error message. I went from VC2008 to VC2012 and I'm getting this error. Not sure why. Previous error was fixed by #include <iterator> on a different computer. Current computer is generating this error.

    error C2784: void STLCopy(tSTLContainer *,const tSTLContainer *)' : could not deduce template argument for 'tSTLContainer *' from 'std::vector<_Ty,_Alloc>'

    Code:
    template 
    <
    	class tSTLContainer			// The type of STL container to copy.
    >
    void STLCopy (tSTLContainer* outDest, const tSTLContainer* inSource)
    {
    	copy(inSource->begin(), inSource->end(), insert_iterator<tSTLContainer>(outDest, outDest->begin()));
    }
    Once again, never mind. Changing pointers to references fixed it, but I'm not sure why.
    Last edited by GCDEF; June 10th, 2013 at 09:48 AM.

  2. #2
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,721

    Re: Now what's wrong with this STL code

    Once again, never mind. Changing pointers to references fixed it, but I'm not sure why.
    1. That would have been my suggestion.

    2. Keeping as pointers:

    Code:
    copy(inSource->begin(), inSource->end(), insert_iterator<tSTLContainer>(*outDest, outDest->begin()));
    
    std::vector<int> v1;
    std::vector<int> v2;
    STLCopy(&v2,&v1);

  3. #3
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Now what's wrong with this STL code

    And that prooves the point I made in that other thread. pointers confuse programmers (even seasoned ones) :-)

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