作爲相當新的C++,我不太明白一些指令我遇到如:裏面的Structs用C++的#define
#ifndef BOT_H_
#define BOT_H_
#include "State.h"
/*
This struct represents your bot in the game of Ants
*/
struct Bot
{
State state;
Bot();
void playGame(); //plays a single game of Ants
void makeMoves(); //makes moves for a single turn
void endTurn(); //indicates to the engine that it has made its moves
};
#endif //BOT_H_
什麼我不明白是「的#ifndef BOT_H_」和「#定義 - #ENDIF」
從我收集的東西,它定義如果在預編譯器在它看起來它尚未定義的常量BOT_H_。我實際上並不知道它裏面的結構是一個常量,它是如何讓我訪問它裏面的函數的。
我也不明白爲什麼我們這樣做?我之前使用過C++,而且沒有使用.h文件,所以它可能很容易丟失。
@downvoter,照顧評論你認爲與這個答案扭曲? – svick
謝謝,我現在明白了! –