Reputation: 135
I got a array of this kind
VehicleTwoD *vehicletwod[100];
Then i create this vector
vector<VechicleTwoD*> sortVector;
Then i did this
//arrayCounter is an integer that record the element count of array vehicletwod
sortVector.assign(vehicletwod, vehicletwod+ arrayCounter);
But now i try call a function of vehicletwod by using
sortVector->getName();
It doesnt work, error message was sortVector does not have such function. how can i retrieve it or its impossible?
Upvotes: 0
Views: 78
Reputation: 8027
It's possible you just need to say which element of the vector you want to call.
sortVector[i]->getName();
Upvotes: 0
Reputation: 2292
Did you mean to invoke the function on sortVector[0]
? (or any other member of the aggregate?)
Upvotes: 0
Reputation: 258618
sortVector
is of type vector<VehicleTwoD*>
(I'm assuming that's what you meant), so it doesn't have that method. You probably want to call the method on an element in vector, in which case you can do:
sortVector[0]->getName();
which would call the method on the vector's first element.
Upvotes: 2