I do not know why this code cannot be compiled. I'v tested in Visual C ++ 2010 and gcc with -std = C ++ 0x. Does anyone give any 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; }
compilation error: 'void Foo :: test (T)': member function already defined or declared
but why can this 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 & and == T &, therefore const T & and == const T &
source share