一些C++11语言新特性

1. Uniform Initialization

int values[] { 1, 2, 3 };
std::vector<int> v { 2, 3, 5, 7, 11, 13, 17 };
std::vector<std::string> cities {
"Berlin", "New York", "London", "Braunschweig", "Cairo", "Cologne"
};
std::complex<double> c{4.0,3.0}; // equivalent to c(4.0,3.0)
int i; // i has undefined value
int j{}; // j is initialized by 0
int* p; // p has undefined value
int* q{}; // q is initialized by nullptr

std::initializer_list<>

void print (std::initializer_list<int> vals)
{
    for (auto p=vals.begin(); p!=vals.end(); ++p) { // process a list of values
        std::cout << *p << "
";
    }
}

// call func
print ({12,3,5,7,11,13,17}); // pass a list of values to print()
原文地址:https://www.cnblogs.com/davidgu/p/4607849.html