最近、「Effective C++ 」という本を読みましたが、項目 35 に typedef に関する宣言があり、混乱しています。
class GameCharacter; // Question1: Why use forward declaration?
int defaultHealthCalc(const GameCharacter& gc);
class GameCharacter{
public:
typedef int (*HealthCalcFunc)(const GameCharacter&); // Question 2: What does this mean?
explicit GameCharacter(HealthCalcFunc hcf = defaultHealthCalc)
: healthFunc(hcf)
{}
int healthValue() const
{return healthFunc(*this); }
private:
HealthCalcFunc healthFunc;
};
だから私の最初の質問は、なぜ著者はここで前方宣言を使用するのですか? 具体的な理由はありますか?
2 番目の質問は、typedef 宣言をどのように理解し、どのように使用するかです。私はただのようなことを知っていますtypedef int MyInt;