I have been given an assignment to split up a program into different files. The assignment was: Each of the files should contain the following: customers.h: should contain the definition of the customer structure and the declaration of print customers. customers.cpp: should contain the implementation (or definition) for print customers. exercise 1 5.cpp: should contain an include of customers.h and the main program.
Here is my code:
customers.h
#pragma once;
void print_customers(customer &head);
struct customer
{
string name;
customer *next;
};
customers.cpp
#include <iostream>
using namespace std;
void print_customers(customer &head)
{
customer *cur = &head;
while (cur != NULL)
{
cout << cur->name << endl;
cur = cur->next;
}
}
exercise_1_5.cpp
#include <iostream>
#include <string>
#include "customers.h"
using namespace std;
main()
{
customer customer1, customer2, customer3;
customer1.next = &customer2;
customer2.next = &customer3;
customer3.next = NULL;
customer1.name = "Jack";
customer2.name = "Jane";
customer3.name = "Joe";
print_customers(customer1);
return 0;
}
It compiles and runs fine in a single program but when i try to split it up and compile with g++ -o customers.cpp
I receive this error
customers.cpp:4:22: error: variable or field ‘print_customers’ declared void
customers.cpp:4:22: error: ‘customer’ was not declared in this scope
customers.cpp:4:32: error: ‘head’ was not declared in this scope
Can anyone help, I am just a beginner with c++