If you don't need to modify the vector<void*> foo
then you could just work with the underlying data, by changing your function signature to: void SetDataReferences(MyStruct*const* pVector, const size_t length)
(remember that const
is left associative, so this is a pointer-to-constant-pointers-to-MyStructs.) This can be called as follows:
SetDataReferences(reinterpret_cast<MyStruct*const*>(data(foo)), size(foo))
If you needed to modify the elements of vector<void*> foo
(not the size) you still have the recourse of changing your function signature to: void SetDataReferences(MyStruct** pVector, const size_t length)
This can be called as follows:
SetDataReferences(reinterpret_cast<int**>(data(foo)), size(foo))
Live Examples
If you need to modify vector<void*> foo
that gets more complicated, you'll need to accept the vector<void*>
as your function signature does in the question and cast the elements on use rather than as a group.