c++ - Preserving referenceness when passing variadic arguments -
consider following code snippet:
class base { public: template <typename...ts> void fun(ts... vs) { cout << "base::fun" << endl; cout << __funcsig__ << endl; } }; template <typename...ts> class derived : public base { public: void dfun(ts... vs) { cout << "derived::dfun" << endl; cout << __funcsig__ << endl; fun(vs...); } }; int main() { int = 10; int & = i; derived<int, int &> d; d.dfun(i, a); }
on running above code in vs2013, types deduced paramater pack values in derived::dfun (int, int&) in base::fun (int, int). why referenceness lost when passing arguments?
if dfun , fun free functions, referenceness preserved. why difference?
if change signature of base::fun base::fun(ts&&... vs), referenceness preserved again.
during template deduction reference types deduced type refer to. int&
deduced int
. causing behaviour seeing.
see here more detailed explication.
Comments
Post a Comment