B
barcaroller
Can anyone tell me why the first block of code fails to compile, while the
second works fine.
Block 1
=======
vector<int> myvector;
string mystr;
void foo( vector<int>::const_iterator begin,
vector<int>::const_iterator end )
{
myvector.assign(begin, end);
}
//
// Compiler error; string iterators not accepted as vector iterators
//
foo(mystr.begin(), mystr.end());
gcc output
-----------
error: conversion from '__gnu_cxx::__normal_iterator,
std::allocator > >' to non-scalar type
'__gnu_cxx::__normal_iterator > >' requested
Block 2
=======
//
// But this works; string iterators accepted as vector iterators
//
myvector.assign(mystr.begin(), mystr.end());
second works fine.
Block 1
=======
vector<int> myvector;
string mystr;
void foo( vector<int>::const_iterator begin,
vector<int>::const_iterator end )
{
myvector.assign(begin, end);
}
//
// Compiler error; string iterators not accepted as vector iterators
//
foo(mystr.begin(), mystr.end());
gcc output
-----------
error: conversion from '__gnu_cxx::__normal_iterator,
std::allocator > >' to non-scalar type
'__gnu_cxx::__normal_iterator > >' requested
Block 2
=======
//
// But this works; string iterators accepted as vector iterators
//
myvector.assign(mystr.begin(), mystr.end());