プログラムを複数のファイルに分割する任務を与えられました。割り当ては次のとおりです。 各ファイルには次のものが含まれている必要があります。 customers.h: 顧客構造の定義と印刷顧客の宣言が含まれている必要があります。customers.cpp: 印刷顧客向けの実装 (または定義) を含める必要があります。演習 1 5.cpp: customers.h とメイン プログラムのインクルードを含める必要があります。
これが私のコードです:
顧客.h
#pragma once;
void print_customers(customer &head);
struct customer
{
string name;
customer *next;
};
顧客.cpp
#include <iostream>
using namespace std;
void print_customers(customer &head)
{
customer *cur = &head;
while (cur != NULL)
{
cout << cur->name << endl;
cur = cur->next;
}
}
練習_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;
}
単一のプログラムでコンパイルして正常に実行されますが、分割してコンパイルしようとするとg++ -o customers.cpp
このエラーが表示されます
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
誰でも助けてもらえますか、私はC ++の初心者です