First, I apologize for any concept errors about C++. I am pretty new.
I am having trouble iterating through each node of a passed linked list. What I have right now is an implementation file with a few functions. The class is called listClass and has a private member function of
list<coordStruct> coordinates;
. A standard stucture has also been set up called coordStruct that has two elements, x and y.
It appears that my problem is how I use the passed-in class. I have it as passedIn->coordinates.begin() and it gives an error. When using Visual Studio and intellisense, it shows that passedIn-> has no member functions, but passedIn. does and it has the coordinates associated. So I tried using passedIn.coordinates.begin() but I get a different error.
I have summarized my problem with the two snippets of code below:
this works:
listClass& listClass::printCoords()
{
list<coordStruct>::iterator i;
for (i = this->coordinates.begin(); i != this->coordinates.end(); i++) {
cout << "x: " << (*i).x << ", y: " << (*i).y) << endl;
}
}
This doesn't work. It gives an error of error C2679: binary '=' : no operator found which takes a right-hand operand of type 'std::list<_Ty>::_Const_iterator<_Secure_validation>' (or there is no acceptable conversion). It points to the start of the for loop
listClass& listClass::operator=(const listClass &passedIn)
{
this->coordinates.clear();
list<coordStruct>::iterator i;
for (i = passedIn->coordinates.begin(); i != passedIn->coordinates.end(); i++) {
this->insertNode((*i).x, (*i).y);
}
}