I’ve been reading this CodeProject article on C++0x and have given it a quick try in VC2010. However I’ve run into a compile error and I’m at a bit of a loss as to what the problem is.
#include < iostream>
template <typename FirstType, typename SecondType>
auto AddThem(FirstType t1, SecondType t1) -> decltype(t1 + t2)
{
return t1 + t2;
}
int main()
{
auto a = 3.14;
auto b = 3;
auto c = AddThem<decltype(a),decltype(b)>(a,b);
std::cout << c << std::endl;
return 0;
}
Results in this error:
error C2086: ‘FirstType t1’ : redefinition 1> main.cpp(4) :
see declaration of ‘t1′
1>main.cpp(14): error C2780:
”unknown-type’ AddThem(FirstType)’ :
expects 1 arguments – 2 provided 1>
main.cpp(4) : see declaration of
‘AddThem’ 1>main.cpp(14): fatal error
C1903: unable to recover from previous
error(s); stopping compilation
Thanks for any ideas.
It’s because you named both of your parameters
t1. You probably meant to call the second onet2.