次のように、ヘッダー ファイルで配列を宣言しました。
private:
int frames[10];
そして、次のようにクラス コンストラクターに値を割り当てます。
file.open(File);
if(file.is_open())
{
std::string line;
getline(file, line);
std::string param[10];
std::stringstream stream(line);
int n=0;
while(!stream.eof())
{
getline(stream, param[n], '$');
frames[n] = atoi(param[n].c_str());
n++;
}
file.close();
}
後で、この配列は関数で使用されます。
currentFrame++;
if(frames[currentAnimation] <= currentFrame)
{
currentFrame = 0;
}
コードを実行すると、セグメンテーション エラーが発生し、gdb は次のように返します。
Program received signal SIGSEGV, Segmentation fault.
0x0000000000402c22 in Sprite::update (this=0x7ffff6efe678 <main_arena+88>) at Sprite.cpp:93 93
if(frames[currentAnimation] <= currentFrame)
(gdb) bt
#0 0x0000000000402c22 in Sprite::update (this=0x7ffff6efe678 <main_arena+88>) at Sprite.cpp:93
#1 0x0000000000401fcb in main (argc=1, argv=0x7fffffffeb88) at main.cpp:146
どこが間違っているのかわかりません。エラーはここのどこかにあると思います。たくさんのコードがあるので、すべてのコードを掲載することはできませんが、具体的な情報が必要な場合は、お問い合わせください。
事前にどうもありがとうございました。