さて、私はHTML / Javascript / PHPの専門家ですが、C++を学ぼうとしています。私はまだ初心者で、エラーのあるC++プログラミングプロジェクトがあります。
int main()を含むファイルは'football.cpp'であり、使用する必要のある3つのクラス(Game、Team、およびDate)の.hファイルと.cppファイルがあります。チームの各インスタンスにはゲームのベクトルが含まれ、各ゲームには日付が含まれます。Dateには、他のクラスのインスタンスは含まれていません。
コンパイル時にエラーが発生しないように、ファイルの先頭で#includeステートメントと#ifndefステートメントを使用する方法を見つけようとしていますが、機能する組み合わせが見つかりません。他にバグがあるかどうかはわかりません。これが私の現在の#includeセクションであり、他のライブラリは数えていません。
サッカー.cpp
#include "game.h"
#include "team.h"
#include "date.h"
team.h
#ifndef __game_h_
#define __game_h_
#endif
team.cpp
#include "team.h"
#ifndef __game_h_
#define __game_h_
#endif
game.h
#ifndef __date_h_
#define __date_h_
#endif
game.cpp
#include "game.h"
#ifndef __date_h_
#define __date_h_
#endif
date.cpp
#include "date.h"
私はCygwing++コンパイラを使用しており、コンパイルに使用する行は次のとおりです。
g++ football.cpp team.cpp game.cpp date.cpp -o football.exe
これが私が得るすべてのエラーです:(警告、テキストの壁)
$ g++ football.cpp team.cpp game.cpp date.cpp -o football.exe
In file included from football.cpp:9:0:
game.h:15:96: error: ‘Date’ has not been declared
game.h:24:1: error: ‘Date’ does not name a type
game.h:37:1: error: ‘Date’ does not name a type
football.cpp: In function ‘int main(int, char*)’:
football.cpp:65:70: error: no matching function for call to ‘Game::Game(std::string&, std::string&, int [5], int [5], Date&)’
game.h:15:1: note: candidates are: Game::Game(std::string, std::string, const int, const int*, int)
game.h:14:1: note: Game::Game()
game.h:10:12: note: Game::Game(const Game&)
In file included from team.cpp:4:0:
team.h:24:8: error: ‘Game’ was not declared in this scope
team.h:24:12: error: template argument 1 is invalid
team.h:24:12: error: template argument 2 is invalid
team.cpp: In member function ‘float Team::getStat3()’:
team.cpp:36:26: error: request for member ‘size’ in ‘((Team*)this)->Team::games’, which is of non-class type ‘int’
team.cpp:37:21: error: invalid types ‘int[int]’ for array subscript
team.cpp:37:50: error: invalid types ‘int[int]’ for array subscript
team.cpp:38:21: error: invalid types ‘int[int]’ for array subscript
team.cpp:38:47: error: invalid types ‘int[int]’ for array subscript
team.cpp:38:76: error: invalid types ‘int[int]’ for array subscript
team.cpp:38:106: error: invalid types ‘int[int]’ for array subscript
team.cpp: In function ‘bool compare2(Team, Team)’:
team.cpp:45:39: error: request for member ‘size’ in ‘t1.Team::games’, which is of non-class type ‘const int’
team.cpp:46:39: error: request for member ‘size’ in ‘t2.Team::games’, which is of non-class type ‘const int’
team.cpp:50:17: error: request for member ‘size’ in ‘t1.Team::games’, which is of non-class type ‘const int’
team.cpp:50:35: error: request for member ‘size’ in ‘t2.Team::games’, which is of non-class type ‘const int’
team.cpp:52:24: error: request for member ‘size’ in ‘t1.Team::games’, which is of non-class type ‘const int’
team.cpp:52:43: error: request for member ‘size’ in ‘t2.Team::games’, which is of non-class type ‘const int’
team.cpp: In function ‘bool compare3(Team, Team)’:
team.cpp:62:29: error: passing ‘const Team’ as ‘this’ argument of ‘float Team::getStat3()’ discards qualifiers
team.cpp:63:29: error: passing ‘const Team’ as ‘this’ argument of ‘float Team::getStat3()’ discards qualifiers
In file included from game.cpp:5:0:
game.h:15:96: error: ‘Date’ has not been declared
game.h:24:1: error: ‘Date’ does not name a type
game.h:37:1: error: ‘Date’ does not name a type
game.cpp: In constructor ‘Game::Game()’:
game.cpp:26:3: error: ‘date’ was not declared in this scope
game.cpp:26:15: error: ‘Date’ was not declared in this scope
game.cpp: At global scope:
game.cpp:29:94: error: ‘Date’ has not been declared
game.cpp:29:1: error: prototype for ‘Game::Game(std::string, std::string, int*, int*, int)’ does not match any in class ‘Game’
game.h:10:12: error: candidates are: Game::Game(const Game&)
game.h:15:1: error: Game::Game(std::string, std::string, const int*, const int*, int)
game.cpp:13:1: error: Game::Game()
game.cpp: In member function ‘int Game::getVisitingScore(int) const’:
game.cpp:80:10: error: ‘visitingScores’ was not declared in this scope
game.cpp: At global scope:
game.cpp:94:1: error: ‘Date’ does not name a type
さらに明確にする必要がある場合は編集しますが、そうなるとは思いません。
どんな助けでも大歓迎です。