一些C++11语言新特性 - Uniform Initialization

1. Uniform Initialization

int values[] { , ,  };
std::vector<int> v { , , , , , , };
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 << "\n";
}
} // call func
print ({,,,,,,}); // pass a list of values to print()
上一篇:c# 枚举的定义,枚举的用法,获取枚举值


下一篇:C++构造函数使用的多种方法