I don't know why these code can't be compiled. I'v tested in Visual c++ 2010 and gcc with -std=c++0x. anyone give some suggestion? thanks!
template<typename T>
class Foo
{
public:
void test(const T&){cout<<"const";}
void test( T&){cout<<"non const";}
};
int main()
{
int a;
Foo<int&> f;
}
compile error: 'void Foo::test(T)' : member function already defined or declared
but why this can be compiled?
template<typename T> void foo(const T&){cout<<"const"; }
template<typename T> void foo( T&){cout<<"non const"; }
int main()
{
int a;
foo<int&>(a);
}
i'v read c++0x article said: T& & ==T& , so const T& & == const T& ?