#include <vector>
std::vector<char> x;
/* x is filled with values */
void someFunction(char *);
std::vector<char>::iterator xit(x.begin());
someFunction(static_cast<char *>(xit));
MyFile.cpp(7) : error C2440: 'static_cast' : cannot convert from
'std::vector<_Ty>::iterator' to 'const char *'
with
[
_Ty=char
]
No user-defined-conversion operator available that can perform this
conversion, or the operator cannot be called
someFunction(reinterpret_cast<char *>(xit));
MyFile.cpp(7) : error C2440: 'reinterpret_cast' : cannot convert from
'std::vector<_Ty>::iterator' to 'char *'
with
[
_Ty=char
]
Conversion requires a constructor or user-defined-conversion operator, which
can't be used by const_cast or reinterpret_cast
someFunction(&*xit);
--
Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
someFunction(&(*xit));
To get a pointer to the object an iterator is pointing at, use the
following:
&(*iter)
> #include <vector>
>
> std::vector<char> x;
> /* x is filled with values */
> void someFunction(char *);
> std::vector<char>::iterator xit(x.begin());
>
> someFunction(static_cast<char *>(xit));
>
> MyFile.cpp(7) : error C2440: 'static_cast' : cannot convert from
> 'std::vector<_Ty>::iterator' to 'const char *'
> with
> [
> _Ty=char
> ]
> No user-defined-conversion operator available that can perform this
> conversion, or the operator cannot be called
>
> someFunction(reinterpret_cast<char *>(xit));
>
> MyFile.cpp(7) : error C2440: 'reinterpret_cast' : cannot convert from
> 'std::vector<_Ty>::iterator' to 'char *'
> with
> [
> _Ty=char
> ]
> Conversion requires a constructor or user-defined-conversion operator,
which
> can't be used by const_cast or reinterpret_cast
Why didn't you use std::string?
---
Cheers,
Tom Tempelaere
"Edward Diener" <eddi...@tropicsoft.com> 写入邮件
news:uqWGG5P9...@TK2MSFTNGP10.phx.gbl...