1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| void fun(int& a) { cout << "fun(int& a)" << endl; } void fun(const int& a) { cout << "fun(const int& a)" << endl; } void fun(int&& a) { cout << "fun(int&& a)" << endl; } template<class T> void fac(T&& tmp) { fun(tmp); fun(std::forward<T>(tmp)); } int main() { int a = 10; const int b = 20; fac(a); fac(b); fac(20); return 0; }
|