以下のようにTestクラスを作り,コンストラクタで画像を読み込もうとすると失敗してしまいます。
ちなみにメンバ関数Draw()内で読み込んだ場合は失敗しませんでした。
なぜコンストラクタでの読み込みは失敗するのでしょうか?
#include "DxLib.h"
class Test
{
private:
int img_handle; //画像ハンドル
public:
Test();
void Draw(); //画像描写
};
Test::Test()
{
img_handle = LoadGraph( "パス" ); //エラー(-1を返す)
}
void Test::Draw()
{
/* ここでLoadGraphを使うとエラーなし */
DrawGraph( 0, 0, img_handle, TRUE ); //読み込んだ画像を表示
}
Test test;
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
if( ChangeWindowMode(TRUE) != DX_CHANGESCREEN_OK || DxLib_Init() == -1 ){
return -1;
}
test.Draw();
WaitKey();
DxLib_End();
return 0;
}
画像読み込みエラー
Re:画像読み込みエラー
Test::Test() { this->img_handle = LoadGraph( "パス" ); //エラー(-1を返す) }でも同様な結果を得ることができます。