It sounds like you want to "create a function that can multiply arrays" that will be used "for a lot of different dimensions."
I would deal with this just like I would deal with a vector
output operator: use templates with recursion!
If I wanted to make a function to sum all of the numbers in two vector
's when I add them, I could do:
template <typename T>
int operator+(std::vector<T> v1, std::vector<T> v2) {
if(v1.size() != v2.size()) { throw; } //for simplicity
int sum = 0;
for(size_t x = 0; x < v1.size(); x++) {
sum += v1.at(x) + v2.at(x);
}
return sum;
}
Note that the magic here is in the line
sum += v1.at(x) + v2.at(x);
If v1.at(x)
and v2.at(x)
are std::vector
's, we'll just recursively call this function again. But if they're int
's, we'll add them into sum
and move on.
You can see this in action here: ideone
You could do something similar for your array multiplication. Break the problem down into smaller pieces so you can use recursion and let the templates handle the rest!