stat.h で非常に奇妙な問題が発生しています
コードの先頭に、次の宣言があります。
#include <sys\types.h>
#include <sys\stat.h>
関数プロトタイプ:
int FileSize(string szFileName);
最後に、関数自体は次のように定義されます。
int FileSize(string szFileName)
{
struct stat fileStat;
int err = stat( szFileName.c_str(), &fileStat );
if (0 != err) return 0;
return fileStat.st_size;
}
このコードをコンパイルしようとすると、次のエラーが発生します。
divide.cpp: In function 'int FileSize(std::string)':
divide.cpp:216: error: aggregate 'stat fileStat' has incomplete type and cannot be defined
divide.cpp:217: error: invalid use of incomplete type 'struct stat'
divide.cpp:216: error: forward declaration of 'struct stat'
このスレッドから: C でファイルのサイズを取得するにはどうすればよいですか? このコードは機能すると思いますが、コンパイルできない理由がわかりません。誰かが私が間違っていることを見つけることができますか?