函数返回类型是c++中的vector
function return type is vector in c++
我希望向量作为返回类型的函数在我的代码,如
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<_Ty>'
}
}
class RMLInfoset {
vector<unsigned int> RMLInfoset::getRML(){
return vectDataBlock;
}
}
但显示错误'无法从'std::vector<_Ty>'转换为'std::vector<_Ty>' '所以请大家帮帮我,谢谢。
嗯,部分问题是您从未在Myfun
中实际构建vector v
。
std::vector<int> Myfun() {
std::vector<int> v;
return v;
}
编辑:在问题编辑之后,仍然有一个小问题-您需要将向量声明为std::vector<int>
,而不仅仅是vector<int>
,如上所述。这是因为vector位于std
命名空间中。
你的函数被声明为返回vector<unsigned int>
,但你实际上试图将结果分配给vector<unsigned long>
。它们是不同的类型,不兼容赋值。修改函数声明:
vector<unsigned long> RMLInfoset::getRML(){
您还需要更改vectDataBlock
的类型。基本上,决定你想要使用的向量类型和是一致的
你有三个错误
你没有使用#include <vector>
2)应该是std::vector<int> v;
而不是vector<int> v;
相关文章:
- 替代在python中制作邻接列表与图形问题的字典?(如 C++ 中的 vector<vector<int&g
- 代码中的"vector<<int>vector>&index"是什么意思?
- 命名空间'std'中的'vector'没有模板类型
- dll中的vector.h在我的应用中不可用
- 我应该如何替换 <uint8_t>API 中的 vector::const_iterator?
- 迭代从 SWIG 绑定返回的 python 中的 vector<pair<int,int>>
- C++中的"vector<type[n]>"是什么?
- C++中的 vector 只能读取最后一个元素
- 在这个c++.h文件中,类中的vector需要工作语法
- 查找语句中的"!=vector.end()"是什么意思?
- Vector
与OpenCV中的Vector 的区别 - 对象中的vector中的Push_back
- 比较随机访问迭代器(如 C++ 中的 Vector)时,< >的比较内容是什么?
- 通过在c++中删除vector中的vector来释放内存
- 命名空间'std'中的'vector'不命名类型
- 限制for循环中的vector.size()
- std::vectors中的vector取消分配其shared_ptr内容(堆栈实体对象的使用不正确?)
- c++中的vector下标超出了非空vector的范围
- 在vector中的vector之间移动指针会导致vector迭代器不兼容
- 向循环中的vector添加指针