更新时间:2021-07-11 22:45:45
你传递双重 1.1
到非const引用 T&
。这意味着你必须向构造函数传递一个有效的左值,例如:
You're passing the double 1.1
to a non-const reference T&
. This means you'd have to pass a valid lvalue to the constructor such as by doing:
double x = 4.3;
test<double> d(x);
使构造函数接受const引用( const T&
)和它的工作原理,因为你被允许绑定临时(rvalues)到const引用,4.3技术上是一个临时双。
Make the constructor take a const reference (const T&
) and it works, because you are allowed to bind temporaries (rvalues) to const references, and 4.3 is technically a temporary double.