referencias constantes con typedef y plantillas en c ++
Escuché que los objetos temporales solo pueden asignarse a referencias constantes.
Pero este código da error
#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;
}
El error que se obtiene esinvalid initialization of reference of type 'int&' from expression of type 'const int'