Back to notes -- Keyboard shortcut: 'u'  previous -- Keyboard shortcut: 'p'        Slide program -- Keyboard shortcut: 't'    A similar setup - illustrates that it is not good to return a reference to a deallocated local variable.Lecture 2 - slide 18 : 42
Program 4
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

typedef int T;

const T& f(double d){
  double e = 2 * d;
  return e;                      // Compiler warning:
                                 // returning reference to temporary
}

int main(){
  double expression = 5.3;

  const T &var = f(expression);  
                                 
  cout << var << endl;           // ??
}