I want to pass a dynamic size standard and of typename type array to a function.
I can't figure out how to do it. Why can't I just accept a reference to the object array?
The code I tried:
#include <iostream> #include <array> using namespace std; template <typename T> void showArrays(void *myArrayPointer, int size, T type) { array<T, size> myArray = myArrayPointer; for (int i = 0; i < size; i++) { cout << myArray.at(i) << " \n"; } } int main() { array<int,6> myArray = { 1,2,3,4,5,6 }; cout << "The array is \n"; showArrays(&myArray,6,0); return 0; } But I get expected compile-time constant expression for the Size still. My function header is also not very pretty. But I couldn't figure out a way to have the size dynamic without passing a generic pointer or creating a template of the class array where the size is an attribute.