Back to slide -- Keyboard shortcut: 'u'  previous -- Keyboard shortcut: 'p'  next -- Keyboard shortcut: 'n'          initialization/init3a.cc - Initialization and auto - problems.Lecture 2 - slide 26 : 29
Program 3

// Shows initialization together with auto.
// Best to use = for initialization of variables of auto type.
// Problems in this example.

#include <iostream>

void f(){
  auto x {101};  // x is an object of type initializer_list<int>: A list with a single element.

  // problems here... Does not compile.
  std::cout << "x: " << x << std::endl;   

  // OK - x is a list:
  for(auto element: x){std::cout << element;};   // 101
}

int main(){
  f(); 
}