C++ &引用;错误:与';不匹配;运算符='&引用;将一个矢量复制到另一个矢量

C++ &引用;错误:与';不匹配;运算符='&引用;将一个矢量复制到另一个矢量,c++,vector,struct,C++,Vector,Struct,因此,我创建了一个类的实例,现在我尝试使用getter来获取我拥有的结构向量 struct posesData{ double xInMeters; double yInMeters; double direction; } 现在我创建了RangeandPoseFiles类的一个实例,它加载文件并将其解析为数据结构,即向量 private: char map[50][50]; rangeAndPoseFiles files; vector<posesData> po

因此,我创建了一个类的实例,现在我尝试使用getter来获取我拥有的结构向量

  struct posesData{
double xInMeters;
double yInMeters;
double direction;
}
现在我创建了RangeandPoseFiles类的一个实例,它加载文件并将其解析为数据结构,即向量

private:
  char map[50][50];
  rangeAndPoseFiles files;
  vector<posesData> poses;
  int amountOfValidPoints;
  int discoveredItems[41][8];

public:
 robotAndEnviroment(){
  amountOfValidPoints = 0;
  mapFill();
  poses = files.getPosesData();
  derp();
}
private:
字符映射[50][50];
rangeAndPoseFiles文件;
矢量姿态;
int amountOfValidPoints;
int discoveredItems[41][8];;
公众:
robotAndEnviroment(){
amountOfValidPoints=0;
mapFill();
poses=files.getPosesData();
derp();
}
如您所见,这一行“poses=files.getPosesData();”就是产生错误的地方

    central:~/cpp $ clear && g++ -g -W -Wall -Wextra -pedantic  -std=c++11 Main.cpp -o main
Main.cpp: In constructor 'robotAndEnviroment::robotAndEnviroment()':
Main.cpp:33:9: error: no match for 'operator=' (operand types are 'std::vector<robotAndEnviroment::posesData>' and 'std::vector<rangeAndPoseFiles::posesData>')
   poses = files.getPosesData();
         ^
Main.cpp:33:9: note: candidates are:
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include/g++-v4/vector:69:0,
                 from Main.cpp:2:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include/g++-v4/bits/vector.tcc:167:5: note: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = robotAndEnviroment::$osesData; _Alloc = std::allocator<robotAndEnviroment::posesData>]
     vector<_Tp, _Alloc>::
     ^
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include/g++-v4/bits/vector.tcc:167:5: note:   no known conversion for argument 1 from 'std::vector<rangeAndPoseFiles::posesData>' to 'const std::vector<robotAndEnviroment:$posesData>&'
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include/g++-v4/vector:64:0,
                 from Main.cpp:2:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include/g++-v4/bits/stl_vector.h:448:7: note: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = robotAndEnviroment::pos$sData; _Alloc = std::allocator<robotAndEnviroment::posesData>]
       operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
       ^
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include/g++-v4/bits/stl_vector.h:448:7: note:   no known conversion for argument 1 from 'std::vector<rangeAndPoseFiles::posesData>' to 'std::vector<robotAndEnviroment::pos$sData>&&'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include/g++-v4/bits/stl_vector.h:470:7: note: std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = robotAndEnviroment::pos$sData; _Alloc = std::allocator<robotAndEnviroment::posesData>]
       operator=(initializer_list<value_type> __l)
       ^
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include/g++-v4/bits/stl_vector.h:470:7: note:   no known conversion for argument 1 from 'std::vector<rangeAndPoseFiles::posesData>' to 'std::initializer_list<robotAndEnvir$ment::posesData>'
central:~/cpp $
central:~/cpp$clear&&g++-g-W-Wall-Wextra-pedantic-std=c++11 Main.cpp-o Main
Main.cpp:在构造函数“robotAndEnviroment::robotAndEnviroment()”中:
Main.cpp:33:9:错误:“运算符=”不匹配(操作数类型为“std::vector”和“std::vector”)
poses=files.getPosesData();
^
Main.cpp:33:9:注:候选人为:
在/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include/g++-v4/vector:69:0中包含的文件中,
来自Main.cpp:2:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include/g++-v4/bits/vector.tcc:167:5:note:std::vector&std::vector::operator=(const std::vector&)[带_Tp=robotAndEnviroment:$osesData;_Alloc=std::allocator]
矢量::
^
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include/g++-v4/bits/vector.tcc:167:5:注意:参数1从“std::vector”到“const std::vector&”的转换未知
在/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include/g++-v4/vector:64:0中包含的文件中,
来自Main.cpp:2:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include/g++-v4/bits/stl_vector.h:448:7:注:std::vector&std::vector::operator=(std::vector&)[with 40; u-Tp=robotAndEnviroment::pos$sData;_-Alloc=std::allocator]
运算符=(vector&&&uuux)noexcept(_Alloc_traits::_S_nothrow_move())
^
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include/g++-v4/bits/stl_vector.h:448:7:注意:参数1从“std::vector”到“std::vector&”的转换未知
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include/g++-v4/bits/stl_vector.h:470:7:注意:std::vector&std::vector::operator=(std::initializer_list)[带有_-Tp=robotAndEnviroment::pos$sData;_-Alloc=std::Alloc分配器]
运算符=(初始值设定项列表)
^
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include/g++-v4/bits/stl_vector.h:470:7:注意:参数1从“std::vector”到“std::initializer_list”的转换未知
中央:~/cpp$

我只想从rangeAndPoseFiles类中获取向量,并将其复制到RobotandViroment类,但我得到了错误,原因是什么?

请注意,一个是
vector
,另一个是
std::vector
,使它们成为不同类型的向量。如果
posesData
robotAndEnviroment
rangeAndPoseFiles
之间相同,则在这两者之外声明一次。错误消息看起来非常自我解释。您正试图将
std::vector
分配给
std::vector
。你确定你的型号正确吗?啊,是的,对不起。我不熟悉C++,我认为如果它有相同的数据类型,不管它是什么类,它都会工作。不管怎样,我现在把它修好了。谢谢大家的帮助:)