I want a function that creates an array for testing purposes:
it can be done using void* but in that case you need to do type casting yourself (as pointed out by @Rob) i.e. using reinterpret_cast operator or similar. Here is a simple example with void*
void* vector(){
int t;
int op;
cout << "Size: \n";
cin >> t;
cout << "Select type\n";
cin >> op;
switch(op) {
case 0:
// Create the array with the selected option...
return reinterpret_cast(new int[t]);
case 1:
// Create the array with the selected option...
return reinterpret_cast(new double[t]);
default:
// Other stuff;
return reinterpret_cast(new float[t]);
}
}
Note: you can look at working of malloc() function, it always returns void* to allocated memory and you have to type cast it yourself e.g malloc(sizeof(int)*t)