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 one t2.
That is my mistake. You should have reported on CodeProject itself. I casually found this topic. Yes, they should be two different names.
Now, one more change I need to do!
加载中,请稍侯......
精彩评论