I have a class with vector of string (lines). I have also iterator for the current line of the vector.
I have a method that fills the lines with another container (also vector) I want to update my iterator of current line that points to the last element.
I do this and it is working fine in my compiler but in my teacher compiler it does not work.
class Document {
...
...
std::vector<std::string> lines;
std::vector<std::string>::iterator currLine;
};
void Document::addLineBefore(std::vector<std::string>::iterator begin, std::vector<std::string>::iterator end)
{
int n = std::distance(begin,end) -1;
currLine = (lines.insert(currLine, begin, end)) + n;
}
My teacher compiler :
*Compile Error:
g++ -std=c++11 main.cpp Editor.cpp Document.cpp
Document.cpp: In member function 'void Document::addLineBefore(std::vector >::iterator, std::vector >::iterator)':
Document.cpp:31:53: error: invalid operands of types 'void' and 'int' to binary 'operator+'
currLine = (lines.insert(currLine, begin, end)) + n;
^*
What is the problem? Or maybe there is a better way to update my iterator to points the last element that added ?
insert
with three parameters returns void. – Thomasg++4.9
. Upgrade your compiler. – rafix07insert
function returnsvoid
. – NicholasM