0

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?

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Did you mean to invoke the function on sortVector[0]? (or any other member of the aggregate?)

Comments

0

It's possible you just need to say which element of the vector you want to call.

sortVector[i]->getName();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.