I can create template functions like this:
template<typename T> T trivialA(T in) { return in; }
template<typename T> T trivialB(T in) { return in; }
// Calculation
int main(int argc, char *argv[]) {
trivialA<int>(1);
trivialB<int>(2);
return 0
}
However, what I would like to do, is something like this (so the user can specify the precision they want):
template<typename T> T trivialA(T in){ return in; }
template<typename T> T trivialB(T in){ return in; }
// Calculation
int main(int argc, char *argv[]) {
type THETYPE = int; //<<<<<<<<<<<<<<< WHAT IS THE CORRECT WAY TO DO THIS?
trivialA<THETYPE>(1);
trivialB<THETYPE>(2);
return 0;
}
So my question is, how can I hold the datatype as a variable and pass it into my template functions?
typedefor ausingstatement.