constant references with typedef and templates in c++

Я слышал, что временные объекты могут быть присвоены только постоянным ссылкам.

Но этот код дает ошибку

#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;
}

Полученная ошибка недопустимая инициализация ссылки типа 'int &' из выражения типа 'const int'

15
задан GManNickG 27 September 2010 в 08:14
поделиться