Conversion from VC6 to VC8
-
While converting some of my old dll which is currently compiled in VC6 and is also running successfully. VC2005 compile is throwing compiler error for this piece of code :-
string MyReturn()
{
return string(reinterpret_cast(vec.begin()), vec.size());
}here return type string is
STL::string
and vec isstl::vector
of typeunsigned char
and i am receiving following error :-error C2440: 'reinterpret_cast' : cannot convert from 'std::_Vector_const_iterator<_Ty,_Alloc>'
to 'const char *'
with
[
_Ty=unsigned char,
_Alloc=std::allocator
]
Conversion requires a constructor or user-defined-conversion operator,
which can't be used by const_cast or reinterpret_castDoes anyone know or can give direction to solve above problem, i have tried many way myself, was successfull in using _myfirst member of vector to resolve the problem, but it started giving some other problem. Thanks in advance
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
Never mind - my own stupidity is the source of every "problem" - Mixturecheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You
-
While converting some of my old dll which is currently compiled in VC6 and is also running successfully. VC2005 compile is throwing compiler error for this piece of code :-
string MyReturn()
{
return string(reinterpret_cast(vec.begin()), vec.size());
}here return type string is
STL::string
and vec isstl::vector
of typeunsigned char
and i am receiving following error :-error C2440: 'reinterpret_cast' : cannot convert from 'std::_Vector_const_iterator<_Ty,_Alloc>'
to 'const char *'
with
[
_Ty=unsigned char,
_Alloc=std::allocator
]
Conversion requires a constructor or user-defined-conversion operator,
which can't be used by const_cast or reinterpret_castDoes anyone know or can give direction to solve above problem, i have tried many way myself, was successfull in using _myfirst member of vector to resolve the problem, but it started giving some other problem. Thanks in advance
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
Never mind - my own stupidity is the source of every "problem" - Mixturecheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You
Use another
string
constructor.return string(vec.begin(), vec.end());
«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) -
Use another
string
constructor.return string(vec.begin(), vec.end());
«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++)Nope not working :-
error C2665: 'std::basic_string<_Elem,_Traits,_Ax>::basic_string' : none of the 13 overloads could convert all the argument types
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
Never mind - my own stupidity is the source of every "problem" - Mixturecheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You
-
While converting some of my old dll which is currently compiled in VC6 and is also running successfully. VC2005 compile is throwing compiler error for this piece of code :-
string MyReturn()
{
return string(reinterpret_cast(vec.begin()), vec.size());
}here return type string is
STL::string
and vec isstl::vector
of typeunsigned char
and i am receiving following error :-error C2440: 'reinterpret_cast' : cannot convert from 'std::_Vector_const_iterator<_Ty,_Alloc>'
to 'const char *'
with
[
_Ty=unsigned char,
_Alloc=std::allocator
]
Conversion requires a constructor or user-defined-conversion operator,
which can't be used by const_cast or reinterpret_castDoes anyone know or can give direction to solve above problem, i have tried many way myself, was successfull in using _myfirst member of vector to resolve the problem, but it started giving some other problem. Thanks in advance
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
Never mind - my own stupidity is the source of every "problem" - Mixturecheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You
It seems the vector holds unsigned chars while the string holds char. Try:
string((const char*)&vect[0], vect.size());
2 bugs found. > recompile ... 65534 bugs found. :doh:
-
Nope not working :-
error C2665: 'std::basic_string<_Elem,_Traits,_Ax>::basic_string' : none of the 13 overloads could convert all the argument types
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
Never mind - my own stupidity is the source of every "problem" - Mixturecheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You
I tried this first before replying to you and it is working fine. I used Visual Studio 2008 Here is what I tried -
vector<unsigned char> vec;
vec.push_back('A');
vec.push_back('B');
vec.push_back('C');string s(vec.begin(), vec.end());
«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) -
I tried this first before replying to you and it is working fine. I used Visual Studio 2008 Here is what I tried -
vector<unsigned char> vec;
vec.push_back('A');
vec.push_back('B');
vec.push_back('C');string s(vec.begin(), vec.end());
«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++)«_Superman_» wrote:
I used Visual Studio 2008
Apology, I am using VC8 Aka Visual Studio 2005
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
Never mind - my own stupidity is the source of every "problem" - Mixturecheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You