Member function add should be defined the following way
void Contacts::add( const string &l, const string &f, int a )
{
head = new people { l, f, a, head };
}
Or if your compiler does not support initializer lists with the new operator then
void Contacts::add( const string &l, const string &f, int a )
{
people *p = new people;
p->last = l;
p->first = f;
p->age = a;
p->next = head;
head = p;
}
Member fuunction display should be declared as
void Contacts::display() const;
and defined as
void Contacts::display() const
{
for ( people *tmp = head; tmp; tmp = tmp->next )
{
cout << tmp->last << endl;
cout << tmp->first << endl;
cout << tmp->age << endl;
cout << endl;
}
}
The other two functions should be defined the following way
void addContact( Contacts &contacts )
{
int n = 0;
cout << "number of contacts " << endl;
cin >> n;
for ( int i = 0; i < n; i++ )
{
string l, f;
int a = 0;
cout << "enter last name ";
cin >> l;
cout << "enter first name ";
cin >> f;
cout << "enter age ";
cin >> a;
contacts.add( l, f, a );
}
}
void display( const Contacts &contacts )
{
contacts.display();
}
And in main you should define an object of type
Contacts contacts;
and use it as the argument of the functions above.