I have a function that returns a Customer
object (not pointer) like this:
Customer CustomerList::retrieve(const int index) const{
if (index<1 || index>size)
return false;
else{
Node *cur = find(index);
return (cur->data);
}
}
This function gets a Customer
object from a CustomerList
(which is a linkedlist).
I'm trying to manipulate the Customer
in the list with following function(this function adds an Account
to the Customer
object.)
list.retrieve(i).addAccount(acc);
However after this function call, Customer
object in CustomerList
doesn't change. I assume that the reason is I return a copy of a Customer
object, not the object itself.
So in order to return the adress of Customer and manipulate it correctly, i make the following changes to my function.
Customer* CustomerList::retrieve(const int index) const{
if (index<1 || index>size)
return false;
else{
Node *cur = find(index);
return &(cur->data);
}
}
And call the manipulating function like that:
list.retrieve(i)->addAccount(acc);
But it gives me a "Access violation reading location 0x00000044." error. What I want to learn is:
- Why doesn't it manipulate the
Customer
object in first place? Is my assumption right? - After I change my functions and function calls, why does it gives me the error I mentioned above?