我正在尝试使用`std :: copy``将一个向量复制到另一个向量
vector<note_name> notes = AppSettings::getAllNotes();
copy(notes.begin(), notes.end(), song.noteList);
Run Code Online (Sandbox Code Playgroud)
该函数getAllNotes()返回a vector<note_name>,noteList是同一类型的公共成员.当我试图跑步时我得到:

所以我认为向量使用类型的事实存在一些问题note_name,但我不知道如何修复它.有任何想法吗?
你也需要一个输出迭代器.如果noteList已经具有所需的尺寸,请说:
copy(notes.begin(), notes.end(), song.noteList.begin());
Run Code Online (Sandbox Code Playgroud)
如果它为空并且您想要插入复制的范围,#include <iterator>并说:
copy(notes.begin(), notes.end(), std::back_inserter(song.noteList));
Run Code Online (Sandbox Code Playgroud)
但是,正如@Mike所指出的那样,说下列之一可能更简单:
song.noteList = notes; // keep both
Run Code Online (Sandbox Code Playgroud)
AppSettings::getAllNotes().swap(song.noteList); // dispose of the temporary
Run Code Online (Sandbox Code Playgroud)