Was wondering if anyone could look at me code stub and see what im doing wrong. Im trying to use a generic structure that holds a vector and im trying to pass it to another class and do a copy on it but the g++ compiler is giving me an error. Im not sure if the copy im tring to make from the showIntData() method at the bottem is legal or not. Any help would be appreciated. Here is the cpp code.
// this works fine and displays the data in the vector
for( itr = Payload->IntVector->begin(); itr != Payload->IntVector->end(); itr++ )
{
cout << "looking for payload data in itr -> " << *itr << endl;
}
/* now i want to create a new copy of the vector and pass it to the displayVector() method */
/* This code below gives me an error at compile time
main.cpp:47: error: no match for operator = in VectorCopy =
Payload->Wrapper::IntVector
void Reciever::showIntData( Wrapper* Payload )
{
IntData::const_iterator itr;
// this works fine and displays the data in the vector
for( itr = Payload->IntVector->begin(); itr != Payload->IntVector->end(); itr++ )
{
cout << "looking for payload data in itr -> " << *itr << endl;
}
/* now i want to create a new copy of the vector and pass it to the displayVector() method */
/* This code below gives me an error at compile time
main.cpp:47: error: no match for operator = in VectorCopy =
Payload->Wrapper::IntVector
// VectorCopy IS A VECTOR OBJECT, not a pointer.
IntData VectorCopy;
// YOU CANNOT ASSIGN this way. IntVector is a pointer to an object.
VectorCopy = Payload->IntVector;
// TRY IT THIS WAY
VectorCopy = *(Payload->IntVector);
this->displayVector(VectorCopy);
*/
}
To be honest with you, I am unclear on why you are trying to make a copy. What is the point? You can pass the vector of the payload directly to the displayVector function.
this->displayVector(*(Payload->IntVector));
Thanks for the reply i will use the code tags from now on. I was just trying different things on the vector copy there so i see what you mean now. Thanks for the help.
Noticed you are using the type as the name of your argument.
even if the compiler isn't giving you an error on this(which I imagine it would), it is probably something to be avoided to prevent confusion.