C ++构造函数错误

时间:2012-03-25 22:47:20

标签: c++ sdl

我为下面的代码得到以下错误:“表达式列表被视为复合表达式”。我不知道什么是错的?

Shoot::Shoot() :
    io( IOManager::getInstance() ),
    count(0),
    locX(0),
    locY(0),
    objWidth(0),
    objHeight(0),
    clock( Clock::getInstance() ),
    ticks(0),
    bulletSurface(io.loadAndSet("images/bullet.bmp", true)), 
    bulletFrame(bulletSurface, 30, 30, 0, 0),
    thebullet(Vector2f(700,760), Vector2f(20,45), "bullet" , &bulletFrame)
           {

           }

宣言:

    private :

          const IOManager& io;
          int count;

          int locX;
          int locY;
          unsigned objWidth;
          unsigned objHeight;
          Clock& clock; 
          unsigned ticks;
          SDL_Surface *bulletSurface;
          Frame bulletFrame;
          Sprite *thebullet;
          Shoot(const Shoot&);
          Shoot& operator=(const Shoot&);

1 个答案:

答案 0 :(得分:2)

问题是thebullet是指针,但您尝试使用Vector2f(700,760), Vector2f(20,45), "bullet" , &bulletFrame对其进行初始化。

我的猜测是你需要thebullet(new Bullet(...)) 1

<小时/> <子> 1。虽然如果是,我强烈建议您不要使用原始指针和手动内存管理,而是调查智能指针。