-
June 6th, 2013, 12:41 PM
#1
[RESOLVED] What's wrong with this STL code
Compiled in 2008, gives error C2275, illegal use of this type as an expression in 2012
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()));
}
Never mind. Apparently you need to #include <iterator> now.
Last edited by GCDEF; June 6th, 2013 at 01:12 PM.
-
June 6th, 2013, 01:17 PM
#2
Re: [RESOLVED] What's wrong with this STL code
I don't have 2012 in front of me, but maybe you forgot to include <iterator>?
Here is a full code example
Code:
#include <algorithm>
#include <iterator>
#include <vector>
#include <set>
#include <map>
using namespace std;
template <class tSTLContainer>
void STLCopy (tSTLContainer& outDest, const tSTLContainer& inSource)
{
std::copy(inSource.begin(), inSource.end(), std::insert_iterator<tSTLContainer>(outDest, outDest.begin()));
}
int main()
{
std::map<int, int> InMap, OutMap;
STLCopy(OutMap, InMap);
std::set<int> InSet, OutSet;
STLCopy(OutSet, InSet);
std::vector<int> InVect, OutVect;
STLCopy(OutVect, InVect);
return 0;
}
Regards,
Paul McKenzie
-
June 6th, 2013, 01:18 PM
#3
Re: [RESOLVED] What's wrong with this STL code
Already figured that out, but thanks, you're right.
-
June 6th, 2013, 01:37 PM
#4
Re: [RESOLVED] What's wrong with this STL code
Originally Posted by GCDEF
Already figured that out, but thanks, you're right.
The <iterator> header is a real sneaky one in that so many compilers accept code without it being included.
Regards,
Paul McKenzie
-
June 6th, 2013, 02:13 PM
#5
Re: [RESOLVED] What's wrong with this STL code
Originally Posted by Paul McKenzie
The <iterator> header is a real sneaky one in that so many compilers accept code without it being included.
Regards,
Paul McKenzie
<functional> is the same way. Not required in 2008 but necessary in 2012. Got a clean build once I figured those two out.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|