tags:

views:

159

answers:

2

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.

+9  A: 

It’s because you named both of your parameters t1. You probably meant to call the second one t2.

Timwi
Well no kidding. :( Little embarrassed I missed that!
Chris
@Chris: just blame the compiler for not making it obvious ;)
Matthieu M.
What @Matthieu M. said. The compiler error really could be clearer.
Timwi
A: 

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!

Ajay