It's because the automatic template deduction for globalDoSomething
infers T
as int&
.
If you explicitly instantiate the template function with globalDoSomething<int>(b);
like you did for the member function of the template class, it will also fail to compile.
Conversely, if you instantiate the template class with A<int&> a;
, it will successfully compile.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…