C++构造函数错误
C++ constructor error
对于下面的代码段,我得到了以下错误:"表达式列表被视为复合表达式"。我不知道怎么了?
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.如果是,我强烈建议您不要使用原始指针和手动内存管理,而是研究智能指针
相关文章:
- "error: no matching function for call to"构造函数错误
- 为什么类中的ostringstream类型的成员会导致";调用隐含删除复制构造函数";错误
- 模板,函数使用错误的构造函数来复制我的对象
- C++ OpenCV 卡尔曼滤波器构造函数错误
- 不命名构造函数和析构函数上的类型错误
- 处理简单 cpp 类构造函数中的错误
- 类和构造函数中的函数根本不起作用,并且不返回任何错误
- 链接器错误:无法解析构造函数
- 当我尝试通过构造函数分配 char 数组时出现错误
- 没有参数的构造函数给我错误
- 使用复制构造函数的程序输出错误
- 默认构造函数上的分段错误
- 错误: 无效使用非静态数据成员"应用程序::应用程序构造函数"
- 为什么定义复制构造函数会给我错误:无法将类型 'obj&' 的非常量左值引用绑定到类型为"obj"的右值?
- 带有 QWidget 的分段错误构造函数.Qt/C++
- C++错误构造函数参数
- 错误:构造函数未命名类型
- 错误:构造函数在此上下文中受到保护
- 没有匹配的函数错误C++构造函数
- 错误:构造函数的多个定义