ヘッダーファイルの1つは次のとおりです。
#include "stdafx.h"
class AAA
{
public:
std::string strX;
std::string strY;
};
プロジェクトをコンパイルしようとするとエラーが発生します
error C2011: 'AAA' : 'class' type redefinition
プログラムの他の場所ではクラスを再定義していませんAAA
。どうすれば修正できますか?
ベストアンサー1
コードを次のように変更します。
#ifndef AAA_HEADER
#define AAA_HEADER
#include "stdafx.h"
class AAA
{
public:
std::string strX;
std::string strY;
};
#endif
このヘッダー ファイルをソース ファイルに複数回インクルードすると、インクルード ガードによってコンパイラはクラスを 1 回だけ生成するように強制されるため、class redefinition
エラーは発生しません。