referências constantes com typedef e modelos em c ++
Ouvi dizer que os objetos temporários só podem ser atribuídos a referências constantes.
Mas esse código dá erro
#include <iostream.h>
template<class t>
t const& check(){
return t(); //return a temporary object
}
int main(int argc, char** argv){
const int &resCheck = check<int>(); /* fine */
typedef int& ref;
const ref error = check<int>(); / *error */
return 0;
}
O erro que é get éinvalid initialization of reference of type 'int&' from expression of type 'const int'