StackExchange での最初の投稿です。C++ コースの課題があります。Date クラス (月、日、年) と Time クラス (時間、分、AM/PM) の以前の割り当てを使用する Appointment クラスを作成します。プライマリ/構文エラーのほとんどが邪魔にならないと思います。
私の問題は、#includes とヘッダー ファイルを現在どのように行っているかで、日付と時刻のコンストラクターの複数定義エラーが発生することです。 (そして、私はテンプレートについてあまり知りませんが、それらを使用する必要があります。)
私のファイル:
予定.cpp
#include "time.cpp" #include "date.cpp" #include "appointment.h"
Time/Date オブジェクトを作成できるようにする必要があります。.h または .cpp ファイルを使用する必要がありますか?
予定.h
#ifndef _APPOINTMENT_H_ #define _APPOINTMENT_H_ #include <iostream> #include "time.h" #include "date.h"
日付.cpp
#ifndef _DATE_CPP_ #define _DATE_CPP_ #include "date.h"
日付.h
#ifndef _DATE_H_ #define _DATE_H_
時間.cpp
#ifndef _TIME_CPP_ #define _TIME_CPP_ #include "time.h"
time.h
#ifndef _TIME_H_ #define _TIME_H_
以下は、上記のファイルの実装に関連しています。
main.cpp
#include "arrayListType.h" #include "appointment.h" void read(arrayListType<Appointment>&); void output(const arrayListType<Appointment>&); int main() { arrayListType<Appointment> appointments; read(appointments); output(appointments); return 0; }
read.cpp
#include "arrayListType.h" #include "appointment.h" #include <fstream> using namespace std; void read(arrayListType<Appointment>& appointments) {...}
出力.cpp
#include "arrayListType.h" #include "appointment.h" #include <iostream> #include <iomanip> using namespace std; void output(const arrayListType<Appointment>& appointments) {...}
arrayListType.h (すべての実装がテンプレートとして含まれています)
- itemType.h
最後の 2 を参照する必要があるかどうかわかりません。さらに情報を投稿する必要がある場合は、喜んで投稿します。すべてのファイルの圧縮バージョンもあります。