function template does not recognize lvalue
问题 I have a problem in my code Here is simplified version of it : #include <iostream> class A { public : template <class T> void func(T&&)//accept rvalue { std::cout<<"in rvalue\n"; } template <class T> void func(const T&)//accept lvalue { std::cout<<"in lvalue\n"; } }; int main() { A a; double n=3; a.func(n); a.func(5); } I expect the output to be : in lvalue in rvalue but it is in rvalue in rvalue why ?! 回答1: template <class T> void func(T&&) is universal reference forwarding reference . To