#include #include using namespace std; class Person { protected: string name; int age; public: /** * default constructor with no argument */ Person() { name = ""; age = 0; } /** * constructor with name * @param n name of the person */ Person(string n) { name = n; age = 0; } /** * constructor with name and age * @param n name of the person * @param a age of the person */ Person(string n, int a) { name = n; age = a; } /** * print class contents * @param output stream reference * @return output stream reference */ ostream& print(ostream& out) { out << name << ", " << age; return out; } friend ostream& operator<<(ostream& out, Person& p) { return p.print(out); } }; // ==================================== // main function // ==================================== int main() { // call of Person() // Note: don't use Person p1(); remove parenthesis Person p1; // call of Person(string n) Person p2("toto"); // call of Person(string n, int a) Person p3("toto", 10); // define array of Persons Person *tab; // create an array of Persons, call default constructor tab = new Person[10]; // call constructor Person(string n, int a) -std=c++11 tab = new Person[10] { Person("toto", 10) }; for (int i=0; i<10; ++i) { cout << tab[i] << endl; } return 0; }