function return type is vector in c++
i want vector as return type of function in my code like,
class SocketTransportClient{
void sendData(RMLInfoset *info){
vector<unsigned long>::iterator blockIterator;
vector<unsigned long> vectBlock=info->getRML(); // error : error C2440: 'initializing' : cannot convert from 'std::vector<_Ty>' to 'std::vector&l开发者_Python百科t;_Ty>'
}
}
class RMLInfoset {
vector<unsigned int> RMLInfoset::getRML(){
return vectDataBlock;
}
}
but it show an error 'cannot convert from 'std::vector<_Ty>' to 'std::vector<_Ty>' ' so please any one help me, Thanks.
Well, part of the problem is that you never actually build the vector v
in Myfun
.
std::vector<int> Myfun() {
std::vector<int> v;
return v;
}
EDIT:
After the question edit, there is still a small problem - you need to declare the vector as a std::vector<int>
, not just a vector<int>
, as above. This is because vector resides in the std
namespace.
Your function is declared to return vector<unsigned int>
but you're actually trying to assign the result to a vector<unsigned long>
. Those are different types and not assignment-compatible. Change your function declaration:
vector<unsigned long> RMLInfoset::getRML(){
You will also need to change the type of vectDataBlock
. Basically, decide which vector type you want to use and be consistent.
You have three errors
1) You didn't use #include <vector>
2) It should be std::vector<int> v;
instead of vector<int> v;
3) You didn't post all of your code.
精彩评论