Initializer List

Let us understand the concept of initializer list in C++ with the help of an example. Consider a class viz. person, which has data members like age, name and employee dataExample #include <iostream>#include <string>using namespace std;class employeeData { unsigned int m_salary;public: employeeData() { cout << “employeeData default C’tor” << endl; m_salary = 0; } employeeData(unsigned int salary) { cout << “employeeData parameterized C’tor” << endl; m_salary = salary; } employeeData(const employeeData& data) { cout << “employeeData Copy C’tor” << endl; m_salary = data. m_salary; } employeeData& operator=(const employeeData& data) {…

Initializer_list

Let us understand the concept of initializer_list with the help of an example: #include <iostream>#include <vector>#include <initializer_list>using namespace std;#define MAX 10class array{public: array(std::initializer_list<unsigned int> list) { index = 0; for(auto item: list) { arr[index++] = item; } cout  << “C’tor” << endl; } void display() { for (unsigned int i = 0; i < index; ++i) { cout << arr[i] << endl; } }private: unsigned int arr[ MAX]; unsigned short index;};int main(){ array arrObj = {0,1,5,7,8}; arrObj.display(); vector <unsigned int> v = {5,8,9,10,20}; cout << “Entries in vector: ” <<…