My goal is to have a non member function use a template for a return value. This is so I can return a float array, a double array, etc. I get a "couldn't deduce template parameter 'T'" error.
Here is the method I am trying to use:
template<typename T>
T* make(double magnitude, double frequency, double radians, double seconds,
int samplesPerSecond) {
long samples = length(seconds, samplesPerSecond);
T *wave = new T[samples];
for (int i = 0; i < samples; i++) {
wave[i] = magnitude
* sin(
(2.0 * (M_PI) * frequency * i / samplesPerSecond)
+ radians);
}
return wave;
}
I first tried to call the method normally.
double *ds = make(magnitude, frequency, radians, seconds, samplesPerSecond);
I have tried adding the typename after the function name.
double *ds = make<double>(magnitude, frequency, radians, seconds, samplesPerSecond);
I looked over several pages on the web and they have all covered member functions so far and explained that the type cannot be deduced from a return type, so how do you tell the compiler the type?