Modify the program by creating an array of n objects using
pointers. Show the details of n items by using pointers to object concept.
#include<iostream>
#include<string>
using namespace std;
struct Person
{
string Name;
int age;
Person(string _name, int _age):Name(_name), age(_age){}
};
int main()
{
const int N = 4;
Person a("Jack", 25);
Person b("Jane", 27);
Person c("Mike", 30);
Person d("Ann", 23);
Person membs[N]= { a,b,c,d };
Person *arr = membs;
for (Person* i = &arr[0]; i != &arr[N]; i++)
{
cout << "Person " << i->Name << "\tage " << i->age << endl;
}
}
Comments
Leave a comment