I have several structs for a Vector. For example a struct that has position, another that has more elements and its inherited from the first one and so on
It sounds like you might be abusing inheritance where composition might be a better choice.
Could you show us an example we can bash? Uh, I mean critique?
[Edit:] I missed part of your post. See my next post for the follow-up.
I have several functions that deal with Vertex data but I cant bind to one single struct type to pass in the parameters of the function because I may pass a different one.
If inheritance is the proper choice, then you'll want to take references or pointers. Your CreateCollisionAABB for example, could take a vector of references (std::reference_wrapper) like I showed for the 'RotateAround()' function in my previous post.
To convert a vector of Type to a vector of references to that type, I do this:
template<class BaseType, class ContainerType>
std::vector<std::reference_wrapper<const BaseType>> RefWrapAsVector(const ContainerType &container)
{
//Create a vector of std::reference_wrappers wrapping 'BaseType'.
return std::vector<std::reference_wrapper<const BaseType>>(std::begin(container), std::end(container));
}
And use it like this:
void ForceAnimalsToTalk(const std::vector<std::reference_wrapper<const Animal>> &animals)
{
for(const Animal &animal : animals)
{
animal.Talk();
}
}
int main()
{
//Really just an excuse to add moar cats to teh code.
std::vector<Cat> myCats = {Cat("Meow"), Cat("Purr"), Cat("Meowmeow"), Cat("*yawns adorably*")};
ForceAnimalsToTalk(RefWrapAsVector<Animal>(myCats));
return 0;
}
Ideone example
But if inheritance isn't the proper choice for your types, then you probably just want a templated function.
Probably something like this:
template<typename VertexType>
BoundingBox CreateCollisionAABB(const XVector<VertexType> &data)
{
BoundingBox boundingBox;
for(const VertexType &vertex : data)
{
//Will work for any class that has 'x'/'y'/'z' members,
//as long as the types of those members are compatible (castable) with 'ExtendToContains()'
boundingBox.ExtendToContain(vertex.x, vertex.y, vertex.z);
}
return boundingBox;
}
Alternatively, you can go template-crazy, and use vectors of arbitrary types, and take pointer-to-members to retrieve the values, that way the parameters can be of arbitrary variable names. That's pushin' it though.
Or, if your data is POD, you can just take a pointer of bytes, and a stride, and cast internally. Not type-safe, so the burden is on the caller to make sure things are correct, but it is an option.