Having some frustration here, attempting to define a templated function that accepts multiple data types, but Im doing something wrong with the template. Any help is mucho appreciated.
#include <iostream>
#include <string>
usingnamespace std;
template<typename T, typename B, typename C>
T DisplayMin(B temp1[], C temp2[], int size);
int main(){
constint size_t = 5;
string names[size_t];
int prices[size_t];
cout << "enter first array values.\n";
for (int i = 0; i<size_t; i++){
cin >> names[i];
}
cout << "enter 2nd array values.\n";
for (int i = 0; i<size_t; i++){
cin >> prices[i];
}
int DisplayMin(names, prices, size_t);
return 0;
}
template<typename T, typename B, typename C>
T DisplayMin(B temp1[], C temp2[], int size){
if(isdigit(temp1[0])){
int val = temp1[0];
int counter = 0;
for (int i = 0; i < size; i++){
if (val < temp1[i]){
val = temp1[i];
}
counter +=1;
}
cout << "The min value of " << val << " belongs to "<< temp2[counter] << ".\n";
return;
}
elseif(isdigit(temp2[0])){
int val = temp2[0];
int counter = 0;
for (int i = 0; i < size; i++){
if (val < temp2[i]){
val = temp2[i];
}
counter +=1;
}
cout << "The min value of " << val << " belongs to "<< temp1[counter] << ".\n";
return;
}
else {
cout << "Neither arrays contain a min numeric value.\n";
return;
}
}
Well since most of the problems are not template related I suggest you start by getting a non-template class to work before you throw in the complexities of templates. Also when you do get to templates start with a template that only requires one templated parameter.