C++构造函数错误

C++ constructor error

本文关键字:错误 构造函数 C++      更新时间:2023-10-16

对于下面的代码段,我得到了以下错误:"表达式列表被视为复合表达式"。我不知道怎么了?

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)
           {
           }

DE声明:

    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&);

问题是thebullet是一个指针,但您试图用Vector2f(700,760), Vector2f(20,45), "bullet" , &bulletFrame初始化它。

我猜你想要thebullet(new Bullet(...))1


1.如果是,我强烈建议您不要使用原始指针和手动内存管理,而是研究智能指针