0

この関数を持つクラスがあります:

void Render(SDL_Surface *source,SDL_Surface *destination,string img)
{
    SDL_Rect offset;
    offset.x = m_x;
    offset.y = m_y;
    source = IMG_Load(img);
    offset.w = source->w;
    offset.h = source->h;    
}

何らかの理由include <string>で、ヘッダーファイルの先頭にある場合でも、それは許可されません。私は得る:

Identifier, "string" is undefined.

私のメインファイルにこのようなデータを渡します:

btn_quit.Render(menu,screen,"button.png");

私が実行すると私は得る:

'Button::Render' : function does not take 3 arguments

しかし、このサイトはstring、データ型の正しい構文であると言っています(下部):http ://www.cplusplus.com/doc/tutorial/variables/

誰かが私が間違っていることを説明できますか?

4

1 に答える 1

3

レンダリング機能を以下に変更することをお勧めします。

void Render(SDL_Surface *source,SDL_Surface *destination,const std::string& img)
{
    SDL_Rect offset;
    offset.x = m_x;
    offset.y = m_y;
    source = IMG_Load(img.c_str());
    offset.w = source->w;
    offset.h = source->h;    
}
  1. 文字列の代わりにstd::stringを使用する
  2. 値で渡す代わりにimg参照を渡す
  3. change from IMG_Load(img); to IMG_Load(img.c_str());
于 2012-11-04T05:53:12.887 に答える