Dear experts, I have this piece of code:
template <typename genericType = int>
genericType add (genericType a, genericType b)
{
return a + b;
}
int main ()
{
int i1 = 1;
double d2 = 3.14;
std::cout << "Add: " << add<> (i1,d2) << std::endl;
return 0;
}
it gives me the following error at compile time:
test.cpp:14:27: error: no matching function for call to 'add'
std::cout << "Add: " << add<> (i1,d2) << std::endl;
^~~~~
test.cpp:4:13: note: candidate template ignored: deduced conflicting types for parameter 'genericType' ('int' vs. 'double')
genericType add (genericType a, genericType b)
^
1 error generated.
Is there a way that I can cast the arguments to be int?
I thought it was possible with the default template value.
Many thanks,
- Mauro.
What I have tried:
template <typename genericType = int>
genericType add (genericType a, genericType b)
{
return a + b;
}
int main ()
{
int i1 = 1;
double d2 = 3.14;
std::cout << "Add: " << add<> (i1,d2) << std::endl;
return 0;
}