I want a function that creates an array for testing purposes:
I think you should re-think your design.
Rather than trying to write a function that returns an array of user-defined type to test. I would instead call a different test function depending on the user choice.
The test function can be templated to avoid code duplication:
#include
#include
template
void doTest(unsigned size) {
std::vector data(size);
// Do the actual test on the data...
}
int main() {
unsigned size;
std::cout << "Size: \n";
std::cin >> size;
int op;
std::cout << "Select type\n";
std::cin >> op;
switch(op) {
case 0:
doTest(size);
break;
case 1:
default:
doTest(size);
}
}
If you really want to return your array from a function you could wrap it in a polymorphic type. But to actually do anything with the array you would need to call a virtual method on the polymorphic type so I don't see how it buys you anything over calling a test function directly.